In my project I have this problem.
I have a NSDictionary, when I try to call a value sometimes the app crash and Xcode give me this error:
Here is the code to call the value of the dictionary (The value isn't nil):
float valueTest = [[change valueForKey:@"new"] floatValue];
EDIT
This is the structure of my NSDictionary:
{
kind = 1;
new = "0.02696711";
old = "0.04064206";
}
The dictionary is never equal to nil
The method is this:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
}
The dictionary is created by the system. I check with logs the content of the dictionary and it's already correct and already the same format.
I don't have other information.
I'm searching for a method to prevent the crash.
Sorry for possible english errors
Thanks
Okay, it appears we are trying to observe the ISO property of an AVCaptureDevice. And it appears that sometimes it arrives as an NSValue that is not typed as an NSNumber. I don't know why that is, but you can check with this condition:
strcmp(@encode(float), [[change valueForKey:@"new"] objCType]) == 0
If that passes, you can just extract the value directly:
float f;
[[change valueForKey:@"new"] getValue:&f];