我有以下警告(Xcode 10.1 - iOS 12.1)
当我将方法更改为 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];
最佳答案
关闭 secureCoding 解决了这个问题。
[[NSKeyedUnarchiver alloc] initForReadingFromData:data error:&error];
unarchiver.requiresSecureCoding = NO;
[unarchiver decodeObjectForKey:...]
如果您不必向后兼容,最好不要关闭 secureCoding
关于ios - 不推荐使用 initForReadingWithData - initForReadingFromData 返回 nil,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54155209/