如何在NSUserDefaults中设置NSArray? [英] How to set an NSArray in NSUserDefaults?

查看:67
本文介绍了如何在NSUserDefaults中设置NSArray?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么有-arrayForKey:方法,但没有-setArrayForKey:方法。我该如何设置该数组?

I'm wondering why there is a -arrayForKey: method, but no -setArrayForKey: method. How could I set that array?

推荐答案

只需使用 setObject:forKey:。我猜有一个特殊的 arrayForKey: dictionaryForKey:等的原因是,您可以获得更好的类型安全性,而不必不必投。如果使用这些方法,并且默认设置中的元素与类型不匹配,则返回 nil

Just use setObject:forKey:. I guess the reason that there's a special arrayForKey: and dictionaryForKey: etc. is that you get better type safety and don't have to cast. If you use these methods and the element in the defaults does not match the type, then nil is returned.

这篇关于如何在NSUserDefaults中设置NSArray?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆