Tag: MagicalRecord
platform :ios pod 'MagicalRecord'
pod install
mogenerator -m MagicalRecordDemo/MagicalRecordDemo.xcdatamodeld/MagicalRecordDemo.xcdatamodel/ -O MagicalRecordDemo/Models --template-var arc=true
#ifdef __OBJC__ #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> #import <CoreData/CoreData.h> // #define MR_SHORTHAND #import "CoreData+MagicalRecord.h" #endif
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [MagicalRecord setupCoreDataStack]; NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext]; //Personを一つ保存 Person *person = [Person MR_createEntity]; person.name = @"tanaka"; [context MR_saveToPersistentStoreAndWait]; //保存されているPersonを全部表示 NSArray *result = [Person MR_findAll]; int i = 0; for (Person *p in result) { NSLog(@"%d name=%@",i, person.name); i++; } self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; }