How can I use NSError in my iPhone App?

后端 未结 9 1120
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:21

    Objective-C

    NSError *err = [NSError errorWithDomain:@"some_domain"
                                       code:100
                                   userInfo:@{
                                               NSLocalizedDescriptionKey:@"Something went wrong"
                                   }];
    

    Swift 3

    let error = NSError(domain: "some_domain",
                          code: 100,
                      userInfo: [NSLocalizedDescriptionKey: "Something went wrong"])
    

提交回复
热议问题