Reputation: 3203
I need to show error localizedFailureReason for some reason. I am getting NSError
Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Unexpected end of file while parsing object.) UserInfo=0x178a72b80 {NSDebugDescription=Unexpected end of file while parsing object.}
when I try to log
[error localizedFailureReason]
I am getting null value for this. May I know what caused this? I am only getting
The operation couldn’t be completed. (Cocoa error 3840.)
for
[error localizedDescription] only
Below is my complete code for the method:
+(NSDictionary *)insertErrorIntoFormat:(NSError*)error{
NSLog(@"1.%@",[error localizedDescription]);
NSLog(@"2.%@",[error description]);
NSLog(@"3.%@",[self getCurrentDateTimeString]);
NSDictionary *threat = [NSDictionary dictionaryWithObjectsAndKeys:
[self getCurrentDateTimeString], kTimestamp,
[error localizedDescription], @"logs",
[error localizedFailureReason], @"reason",
nil];
return threat;
}
Upvotes: 1
Views: 670
Reputation: 84338
An NSError isn't required to have a failure reason string. It's perfectly valid for it to return nil
. You need to check the return value before you add it to an NSDictionary or NSArray since those data structures cannot contain a nil value.
Upvotes: 1