考虑:
- (void) write: (NSString *) xId data:(NSData *) data forClass: (Class) c {
NSFileManager * fm = [NSFileManager defaultManager] ;
NSString * instancePath = [self instancePath:xId forClass: c] ;
errno = 0 ;
BOOL success = [fm createFileAtPath: instancePath
contents: data
attributes: nil] ;
if (!success) {
::NSLog(@"Couldn't write to path: %@", instancePath) ;
::NSLog(@"Error was code: %d - message: %s", errno, strerror(errno));
} else {
::NSLog(@"COULD write to path: %@", instancePath) ;
::NSLog(@"Error was code: %d - message: %s", errno, strerror(errno));
}
}
然后打印:
2013-03-22 18:59:27.177 otest[18490:303] COULD write to path: /Users/verec/Library/Application Support/iPhone Simulator/6.1/Documents/cal/ModelRepo/ModelRepo#0.sexp
2013-03-22 18:59:27.177 otest[18490:303] Error was code: 3 - message: No such process
2013-03-22 18:59:27.178 otest[18490:303] Couldn't write to path: /Users/verec/Library/Application Support/iPhone Simulator/6.1/Documents/cal/ModelContainer/20130322.sexp
2013-03-22 18:59:27.178 otest[18490:303] Error was code: 3 - message: No such process
- 为什么 errno 不为 0,即使在第一种情况下“成功”为 YES(“可能”情况)
- 任何人都可以发现在第一个(“可能”)情况下成功 = YES 但在第二个(“不能”)情况下成功 = NO 的实际路径中的差异吗?
这是在运行 OCUnit 测试时,Xcode 4.6.1 Simulator 运行 iOS 6.1
我只是感到困惑:-(