How can I use NSError in my iPhone App?

后端 未结 9 1114
Happy的楠姐
Happy的楠姐 2020-12-07 06:32

I am working on catching errors in my app, and I am looking into using NSError. I am slightly confused about how to use it, and how to populate it.

9条回答
  •  悲&欢浪女
    2020-12-07 07:25

    Great answer Alex. One potential issue is the NULL dereference. Apple's reference on Creating and Returning NSError objects

    ...
    [details setValue:@"ran out of money" forKey:NSLocalizedDescriptionKey];
    
    if (error != NULL) {
        // populate the error object with the details
        *error = [NSError errorWithDomain:@"world" code:200 userInfo:details];
    }
    // we couldn't feed the world's children...return nil..sniffle...sniffle
    return nil;
    ...
    

提交回复
热议问题