ios - NSUserDefaults 为 valueForKey 返回 null
<p><p>在我的应用程序中,我试图访问由 libXYZ.a 文件存储的 NSUserDefaults 中的值。但我得到一个空值。
在 lib 文件中保存时我使用 <code>setValue:forKey:</code>,在应用程序中访问时我使用 <code>valueForKey:</code></p>
<p>我们可以在 lib 文件之外访问 userdefaults 吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您应该使用 <code>objectForKey</code> 而不是 <code>valueForKey</code>。它必须在文件中使用 <code>setObject: forKey:</code> 来设置值。 <code>valueForKey</code> 基于 <strong>KVO</strong> 而 <code>objectForKey</code> 基于 <strong>dictionary</strong>。 </p></p>
<p style="font-size: 20px;">关于ios - NSUserDefaults 为 valueForKey 返回 null,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/49318851/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/49318851/
</a>
</p>
页:
[1]