2011-11-04 4 views
-2

이 코드 조각에서 오류가 발생했습니다. 주석에 오류 메시지를 넣었습니다. 그것을 알아낼 수 없습니다.NSError 코드에서 오류 발생

미리 감사드립니다. ";"코드가 오타가없는 경우

#import <Foundation/Foundation.h> 

int main (int argc, const char * argv[]) 
{ 

    @autoreleasepool { 

     NSMutableString *str = [[NSMutableString alloc]init]; 
     for (int i = 0; i < 10; i++) { 
     [str appendString:@"Aaron is cool!\n"]; 
     } 

     // Declare a pointer to an NSError object, but don't instantiate it. 
     // The NSError instance will only be created if there is, in fact, an error. 
     NSError *error = nil; 

     // Pass the error pointer by reference to the NSString method 
     BOOL success =[str writeToFile:@"/tmp/cool.txt"; // Expected "]" 
      atomically:YES // Bad receiver type 'int' 
      encoding:NSUTF8StringEncoding 
       error:&error]; 

     // Test the returned BOOL, and query the NSError if the write failed 
     if (success) { 
     NSLog(@"done writing /tmp/cool.txt"); 
     } else { 
     NSLog(@"writing /tmp/cool/txt failed:@", error localizedDescription); // Expected ')' 
     } 

    } 
    return 0; 
} 

답변

0

이 시도 :

@autoreleasepool { 
    NSMutableString *str = [[[NSMutableString alloc]init] autorelease]; 
    for (int i = 0; i < 10; i++) { 
     [str appendString:@"Aaron is cool!\n"]; 
    } 
    NSError *error = nil; 
    BOOL success =[str writeToFile:@"/tmp/cool.txt" 
         atomically:YES 
          encoding:NSUTF8StringEncoding 
          error:&error]; 
    if (success) { 
     NSLog(@"done writing /tmp/cool.txt"); 
    } else { 
     NSLog(@"writing /tmp/cool/txt failed: %@", [error localizedDescription]); 
    } 

} 
return 0; 
+0

확인, 맞아이었다. 알았다. 고맙습니다. – pdenlinger

1

이 문제

// Pass the error pointer by reference to the NSString method 
     BOOL success =[str writeToFile:@"/tmp/cool.txt"; // Expected "]" 
      atomically:YES // Bad receiver type 'int' 
      encoding:NSUTF8StringEncoding 
       error:&error]; 

세미콜론을 제거하다 여기에서.

BOOL success =[str writeToFile:@"/tmp/cool.txt"; // Expected "]"