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 · Aug 8, 2015 · 2372 views
    This topic created in 4070 days ago, the information mentioned may be changed or developed.

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

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

    2 replies  •  2015-08-08 17:13:00 +08:00
    xhacker
        1
    xhacker  
       Aug 8, 2015
    其实不该把 NSUserDefaults 当数据库用。
    SeanChense
        2
    SeanChense  
    OP
       Aug 8, 2015 via iPhone
    @xhacker 是的😄,一开始就注定了不优雅。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4654 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 08:49 · PVG 16:49 · LAX 01:49 · JFK 04:49
    ♥ Do have faith in what you're doing.