我在Objective C中遇到了一个奇怪的问题。请看下面的代码。
+(BOOL)isWritableCopyofAppConfig{
BOOL response = false;
NSURL *urlConfig = [NSURL URLWithString:APP_CONFIG_PATH];
NSData *dataReturn = [NSData dataWithContentsOfURL:urlConfig];
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0]stringByAppendingPathComponent:@"AppConfig.plist"];
if (dataReturn != nil ){
// It always goes here
}
else{
// Never reach here.
}
return response;
}
即使我将上述if条件更改为以下内容:
if (NO){
// It always goes here even if there is NO.
}
else{
// Never reach here.
}
我尝试清理项目我试过其他的东西,比如直接比较NO == YES仍然会进入第一个区块。
有谁知道如何解决这个或这个行为是什么?
编辑:整个代码
+(BOOL)isWritableCopyofAppConfig{
BOOL response = false;
NSURL *urlConfig = [NSURL URLWithString:APP_CONFIG_PATH];
NSData *dataReturn = [NSData dataWithContentsOfURL:urlConfig];
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0]stringByAppendingPathComponent:@"AppConfig.plist"];
if (NO){
if (filePath != nil){
response = [dataReturn writeToFile:filePath atomically:YES];
}
}
else{
NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"AppConfig" ofType:@".plist"];
[fileMgr copyItemAtPath:resourcePath toPath:filePath error:nil];
}
return response;
}
它是一个类方法(从AppDelegate.m调用):
AppConfigHandler.isWritableCopyofAppConfig();
编辑:调试器的屏幕截图