TL;DR
I am getting an error only on IOS physical device when tapping certain buttons that excecute a certain line of code. I need to interpret the error and find the cause (why only on physical device?)
I am getting this error:
-[NSNull integerValue]: unrecognized selector sent to instance 0x2069e0558 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull integerValue]: unrecognized selector sent to instance 0x2069e0558' *** First throw call stack: (0x1ac9d1288 0x1c5701744 0x1acaaefc0 0x1ac965e98 0x1ac964f70 0x102e9aff0 0x106b80b14 0x10666ba8c 0x1ac636e6c 0x1ac638a30 0x1ac646f48 0x1ac646b98 0x1ac989800 0x1ac943704 0x1ac956bc8 0x1c8ac2374 0x1af2cab58 0x1af04c090 0x10265d384 0x102cb1da4) libc abi: terminating with uncaught exception of type NSException
- thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT frame #0: 0x00000001e4474b38 libsystem_kernel.dylib
__pthread_kill 8 libsystem_kernel.dylib
__pthread_kill: -> 0x1e4474b38 < 8>: b.lo 0x1e4474b58 ; < 40> 0x1e4474b3c < 12>: pacibsp 0x1e4474b40 < 16>: stp x29, x30, [sp, #-0x10]! 0x1e4474b44 < 20>: mov x29, sp Target 0: (Runner) stopped.
Whenever I excecute the following Provider code on the tap of a button:
List<FrediUser>? allFrediUsers = Provider.of<List<FrediUser>>(context);
The actual code seems to have nothing to do with the error, it just triggers it.
Important Notes
- This behaviour ONLY HAPPENS ON iPhone PHYSICAL DEVICE.
- Works in iPad PHYSICAL DEVICE.
- IOS SIMULATOR works as expected
- Works perfectly on android --> This means that there is no error with the provider package nor the code that is looking for that list.
I just need to interpret the error to know what it is exactly! All help wanted!
CodePudding user response:
My solution to this maddening use of NSNull by JSON interpreters is to create a category on NSNull, where I define integerValue, floatValue, length, etc - return 0 for all. Everytime you get another crash add a new category. I think I had 6 or 7 when I had this issue.
The problem with NOT doing this is you have to look for the NULL everywhere in your converted objects - a PITA in my opinion.
EDIT: the code I'm using, all in a NSNull JSON.m file:
@interface NSNull (JSON)
@end
@implementation NSNull (JSON)
- (NSUInteger)length { return 0; }
- (NSInteger)integerValue { return 0; };
- (float)floatValue { return 0; };
- (NSString *)description { return @"0(NSNull)"; }
- (NSArray *)componentsSeparatedByString:(NSString *)separator { return @[]; }
- (id)objectForKey:(id)key { return nil; }
- (BOOL)boolValue { return NO; }
@end
EDIT2: Now in Swift 3:
extension NSNull {
func length() -> Int { return 0 }
func integerValue() -> Int { return 0 }
func floatValue() -> Float { return 0 };
open override var description: String { return "0(NSNull)" }
func componentsSeparatedByString(separator: String) -> [AnyObject] { return [AnyObject]() }
func objectForKey(key: AnyObject) -> AnyObject? { return nil }
func boolValue() -> Bool { return false }
}