创建了一个对象,但它在objective-c,iOS中仍然为null

时间:2013-02-26 16:23:36

标签: ios objective-c

这是我的功能:

- (void) function{
    if (_app.error == nil) {  
        for (Window *window in _app.windows) {
            NSLog(@"test.");
        }

    }
    else {  
        NSLog(@"%@",[_app.error localizedDescription]);
    }
}

而不是进入for循环并打印出“test。”,它从else语句中给我“(null)”。我做错了什么?

+ (App *)loadApp {

NSString *filePath = [self dataFilePath:FALSE];
NSData *xmlData = [[NSMutableData alloc] initWithContentsOfFile:filePath];
NSError *error;
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:xmlData options:0 error:&error];

App *app = [[App alloc] init];

if (doc == nil) app.error = error;

...etc

1 个答案:

答案 0 :(得分:1)

你只是让你的逻辑从前到后;如果没有错误(_app.error == nil):

,您希望继续
- (void) function{
    if (_app.error == nil) {      // NOT !=
        for (Window *window in _app.windows) {
            NSLog(@"test.");
        }

    }
    else {  
        NSLog(@"%@",[_app.error localizedDescription]);
    }
}