magicalrecordの設定
coredataでDBを作成
cocoapodsで「MagicalRecord」をインストール
hogehoge-Prefix.pchを開いて次の1行を追記します。
#import <Availability.h> #ifndef __IPHONE_5_0 #warning "This project uses features only available in iOS SDK 5.0 and later." #endif #ifdef __OBJC__ #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> #import "CoreData+MagicalRecord.h" <<追加 #endif
AppDelegete.mファイルの「didFinishLaunchingWithOptions」に下記を追加
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@"data.sqlite"]; <<追加 return YES; }
AppDelegete.mファイルの「applicationWillTerminate」に下記を追加
- (void)applicationWillTerminate:(UIApplication *)application { [MagicalRecord cleanUp]; <<追加 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. }
NSManagedObject subclassesで作成したもの(Entity)をimport
#import "hogehogehoge.h"
データの取得
NSArray *data = [DATAname MR_findAll];