1.

Explain NSError in Swift.

Answer»

Information about an error condition is encapsulated within an NSError object in an extendable and object-oriented manner. An NSError object is comprised of THREE basic attributes: a predefined error domain (represented as a STRING), a domain-specific error code, and a user info dictionary containing application-specific information. 

EXAMPLE: The examples below show how to CREATE custom errors.

NSString *domain = @"com.MyCompany.MyApplication.ErrorDomain";

NSString *desc = NSLocalizedString(@"Unable to COMPLETE the process", @"");

NSDictionary *userInfo = @{ NSLocalizedDescriptionKey : desc };

NSError *error = [NSError errorWithDomain:domain code:-101 userInfo:userInfo];



Discussion

No Comment Found