我有以下警告(Xcode 10.1 - iOS 12.1)
'initForReadingWithData:'已被弃用:自iOS 12.0起首次弃用-改用-initForReadingFromData:error:*
当我将方法更改为initForReadingFromData时,NSKeyedUnarchiver返回nil。
// Current code which produces the warning (but works fine) :
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
NSMutableArray *loadedCredentialIdentities = (NSMutableArray *)[unarchiver decodeObjectForKey:kStoredCredentialIdentities];
[unarchiver finishDecoding];
...
// using initForReadingFromData produces no warning (but doesn't work - loadedCredentialIdentities is nil) :
NSError *error = nil;
NSKeyedUnarchiver *unarchiver = unarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:data error:&error];
NSMutableArray *loadedCredentialIdentities = (NSMutableArray *)[unarchiver decodeObjectForKey:kStoredCredentialIdentities];
[unarchiver finishDecoding];
unarchiver
为空,则打印“error”。 - rmaddy