Objective c 使用NSCoding解码:密钥是否存在值?

Objective c 使用NSCoding解码:密钥是否存在值?,objective-c,nscoding,Objective C,Nscoding,当使用NSCoding和decoding值时,有没有办法判断给定键是否存在值?换句话说,我想做的是 if([decoder valueExistsForKey:@"myKey"]) //valueExistsForKey is not a real method :( { NSInteger *myInt = [decoder decodeValueForKey:@"myKey"]; } else { //handle special case } 问题是,我的应用程序中有

当使用NSCoding和decoding值时,有没有办法判断给定键是否存在值?换句话说,我想做的是

if([decoder valueExistsForKey:@"myKey"])   //valueExistsForKey is not a real method :(
{
    NSInteger *myInt = [decoder decodeValueForKey:@"myKey"];
}
else
{
    //handle special case
}
问题是,我的应用程序中有旧版本的文档没有“myKey”值,如果没有,则使用0表示myInt(如果解码不存在的密钥会发生什么情况)不是我想要的行为。然而,我不能仅仅解码并检查myInt==0,因为它可能合法地等于0


由于valueExistsForKey方法似乎不存在,我如何复制此行为?

如何?

Derp。谢谢,哈哈。我知道我遗漏了一些东西,似乎我想要的功能是相当标准的功能。。。