gpt4 book ai didi

ios - 不推荐使用 initForReadingWithData - initForReadingFromData 返回 nil

转载 作者:行者123 更新时间:2023-12-01 18:04:31 25 4
gpt4 key购买 nike

我有以下警告(Xcode 10.1 - iOS 12.1)

'initForReadingWithData:' is deprecated: first deprecated in iOS 12.0 - Use -initForReadingFromData:error: instead*



当我将方法更改为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com