V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
SeanChense
V2EX  ›  iDev

如何优雅地在 NSUserDefaults 中实现对旧数据的更新?

  •  
  •   SeanChense · 2015-08-08 16:51:02 +08:00 · 1662 次点击
    这是一个创建于 3198 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我自己的一个类 A,实现了 encodeWithCoder 以及 initWithCoder ,通过 NSKeyedArchiver 实现存储实例对象 a 的功能。
    当我要用 e 更新 a 时,我从一个 key 中取出所有的对象(abcd,其实就是个数组)。
    如何判断从 NSUserDefaults 取出来的 f (内存地址已经改变,不再是当初那个 a,但内容和 a 一致)就是我要想更新的 a ?

    我是给 class A 实现了一个方法 isEqualToA,比较所有属性的内容,property 是 NSString 的就用 isEqualToString 来比较,是 int 就判断是否相等。感觉这么做比较笨,听听大家的高见。

    2 条回复    2015-08-08 17:13:00 +08:00
    xhacker
        1
    xhacker  
       2015-08-08 17:04:10 +08:00
    其实不该把 NSUserDefaults 当数据库用。
    SeanChense
        2
    SeanChense  
    OP
       2015-08-08 17:13:00 +08:00 via iPhone
    @xhacker 是的😄,一开始就注定了不优雅。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1347 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 17:43 · PVG 01:43 · LAX 10:43 · JFK 13:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.