1.4.2.5. 测试(Core Data 应用程序实践指南)

  测试的方法也很简单:

  • 首先,在AppDelegate.h里面引用CoreDataHelper
    @property (strong, nonatomic, readonly)CoreDateHelper *coreDataHelper;

     

  • 初始化CoreDataHelper
    - (CoreDateHelper*)cdh {
        if (debug == 1) {
            NSLog(@"Running %@ '%@'",self.class, NSStringFromSelector(_cmd));
        }
        
        if (!_coreDataHelper) {
            _coreDataHelper = [CoreDateHelper new];
            [_coreDataHelper setupCoreData];
        }
        return _coreDataHelper;
    }

     

  • 在程序转到后台或退出时保存
    [[self cdh] saveContext];

     

 

posted on 2015-11-02 15:44  大木哥  阅读(206)  评论(0编辑  收藏  举报

导航