Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decoding with NSCoding: Does Value Exist For Key?

When using NSCoding and decoding values, is there a way to tell if a value exists for a given key? In other words, what I'm trying to do is...

if([decoder valueExistsForKey:@"myKey"])   //valueExistsForKey is not a real method :(
{
    NSInteger *myInt = [decoder decodeValueForKey:@"myKey"];
}
else
{
    //handle special case
}

The issue is that I have old versions of documents in my app that don't have the "myKey" value, and if they don't have it, using 0 for myInt (what happens if you decode a nonexistent key) is not the behavior I want. However, I can't just decode and check if myInt == 0, because it might legitimately be equal to 0.

Since the valueExistsForKey method does not seem to exist, how can I replicate this behavior?

like image 611
MikeS Avatar asked Aug 14 '12 17:08

MikeS


1 Answers

How about containsValueForKey?

like image 66
mipadi Avatar answered Sep 20 '22 06:09

mipadi