<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                第五節里面,我介紹了CoreData的配置和基本的增刪改查,可能很多人會覺得用它真繁瑣.這里,我再介紹網上大神對它進行了人性化封裝的第三方MagicalRecord,正如FMDB對sqlite進行了封裝一樣,MagicalRecord讓你覺得用CoreData很方便. ? ? ? @基本配置: ? ? ? ? ?1.下載[MagicalRecord](https://github.com/magicalpanda/MagicalRecord),將里面的MagicalRecord文件夾拖入你的工程 ? ? ? ? ?2.確定你創建的工程沒有勾選"Use Core Data" ? ? ? ? ?3.導入CoreData.frame框架 ? ? ? ? ?4.在.pch文件中引入頭文件"CoreData+MagicalRecord.h"(只能,必須在這里引用) ? ? ? ? ?@具體操作: ? ? ? ? ? 1.初始化(在didFinishLaunchingWithOptions中) ~~~ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; HMTRootViewController *rootVC = [[HMTRootViewController alloc] init]; self.window.rootViewController = rootVC; // 初始化 [MagicalRecord setupCoreDataStackWithStoreNamed:@"MT.sqlite"]; [self.window makeKeyAndVisible]; return YES; } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. [MagicalRecord cleanUp]; } ~~~ ![](https://box.kancloud.cn/2016-01-11_569358af50e68.jpg) ? ? ? ? ? 3.增刪改查具體操作 ~~~ - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // 初始化一個Person對象 /** * 這里要注意:默認,xcdatamodeld實體描述表名(name)和類名(class)必須保持一致 * 如果name和class不一致,實現MagicalRecord_MOGenerator協議中得entityName方法來改變 @implementation NSManagedObject (MagicalRecord) + (NSString *) MR_entityName; { NSString *entityName; if ([self respondsToSelector:@selector(entityName)]) { entityName = [self performSelector:@selector(entityName)]; } if ([entityName length] == 0) { entityName = NSStringFromClass(self); } return entityName; } */ Person *person = [Person MR_createEntity]; person.name = @"HMT"; person.sex = @"男"; person.age = @25; } // 添加操作 - (void)addDataOperation{ // 文檔解釋:For any entities to actually be saved / updated / deleted on disk call following method(增加,更新,刪除 都要用這個方法來保存數據) [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];; } // 查詢操作 - (void)selectDataOperation{ // find數據庫中所有的人 NSArray *peoples = [Person MR_findAll]; // find數據庫中第一條記錄 Person *firPerson = [Person MR_findFirst]; // find數據庫中所有name屬性為"HMT"的人并按照年齡age排序 NSArray *otherPeoples = [Person MR_findByAttribute:@"name" withValue:@"HMT" andOrderBy:@"age" ascending:YES]; } // 更新操作 - (void)upDataOperation{ // 選定要修改的人 NSArray *persons = [Person MR_findByAttribute:@"name" withValue:@"HMT"]; for (Person *person in persons) { person.name = @"WDQ"; } [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait]; } // 刪除操作 - (void)deleteDataOperation{ // delete數據庫中所有人 [Person MR_truncateAll]; [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait]; // 根據條件delete特定的某個人 NSArray *persons = [Person MR_findByAttribute:@"name" withValue:@"HMT"]; for (Person *person in persons) { [person MR_deleteEntity]; } [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait]; } ~~~ ? ? ? ? ? 4.額外配置(取消前綴名和不打印日志信息) ~~~ //If you want to omit the "MR_" prefix to all MagicalRecord realted method calls define following before importing the MagicalRecord header #define MR_SHORTHAND //Turn off MagicalRecord logging, again by defining following before header import #define MR_ENABLE_ACTIVE_RECORD_LOGGING 0 ~~~ ? ? ? ? ? ?@以上只是一些基本操作,其他可以自己去查看頭文件
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看