:NS 방법에 의해 반환 된 오류를 처리하는 블록을 사용하는 방법
NSMutableString *tabString = [NSMutableString stringWithCapacity:0]; // it will automatically expand
// write column headings <----- TODO
// now write out the data to be exported
for(int i = 0; i < booksArray.count; i++) {
[tabString appendString:[NSString stringWithFormat:@"%@\t,%@\t,%@\t\n",
[[booksArray objectAtIndex:i] author],
[[booksArray objectAtIndex:i] binding],
[[booksArray objectAtIndex:i] bookDescription]]];
}
if (![self checkForDataFile: @"BnN.tab"]) // does the file exist?
[[NSFileManager defaultManager] createFileAtPath:documentsPath contents: nil attributes:nil]; // create it if not
NSFileHandle *handle;
handle = [NSFileHandle fileHandleForWritingAtPath: [NSString stringWithFormat:@"%@/%@",documentsPath, @"BnN.tab"]]; // <---------- userID?
[handle truncateFileAtOffset:[handle seekToEndOfFile]]; // tell handle where's the file fo write
[handle writeData:[tabString dataUsingEncoding:NSUTF8StringEncoding]]; //position handle cursor to the end of file (why??)
이 내가 (디버깅을 위해) 파일을 다시 읽기 위해 사용하고있는 코드는 다음과 같습니다
를 NSE '호환되지 않는 유형의 매개 변수에보내기'무효 (^) (무효) '
// now read it back NSString* content = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/%@",documentsPath, @"BnN.tab"] encoding:NSUTF8StringEncoding error: ^{ NSLog(@"error: %@", (NSError **)error); }];
나는 말한다 마지막 문장에 2 빌드 오류를 얻고있다 rror * __ autoreleasing의 * '
및 선언되지 않은 식별자의
사용'오류 '
이 내가 방법은 오류를 반환 처리하기 위해 블록을 사용하고 처음입니다; SO 또는 Google에서이 작업을 수행하는 방법을 보여주는 문서를 찾을 수 없습니다. 내가 도대체 뭘 잘못하고있는 겁니까?
블록을 'NSError **'유형의 매개 변수로 전달할 수 있다고 생각하십니까? – rmaddy
어 ... 나는 그것을 예를 들어 보았다 ... 잘못되었다, 응? 그것은 * 블록 *에 문제가 있습니다. SD – SpokaneDude