陈斌彬的技术博客

Stay foolish,stay hungry

MagicalRecord 的使用

1. 将 MagicalRecord 文件夹拖入到工程文件中,引入 CoreData.frame 框架

img

2. 在 .pch 文件中引入头文件 CoreData+MagicalRecord.h4.

img

3. 创建 Model.xcdatamodeld 文件,并创建一个 Teacher 的 ENTITIES,最后创建出 Teacher 类

在 Appdelete.m 文件中写以下代码

img

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    [MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@"mobile.sqlite"];

    Teacher * person = [Teacher MR_createEntity];
    person.name = @"aaa";

    [[NSManagedObjectContext MR_defaultContext]MR_saveToPersistentStoreAndWait];
    NSLog(@"anme is %@",person.name);


    return YES;
}

MagicalRecordhttps://github.com/magicalpanda/MagicalRecord