zoukankan      html  css  js  c++  java
  • 2.11. 创建托管对象(Core Data 应用程序实践指南)

      到现在为止,还没有创建过托管对象,回顾了一下,只是创建了托管对象模型,持久化存储区,持久化存储协调器,托管对象上下文。

      那么,现在就来创建托管对象吧。

      使用NSEntityDescription 的 insertNewObjectForEntityForName来创建

      

    - (void)demo{
        if (debug == 1) {
            NSLog(@"Running %@ '%@'",self.class, NSStringFromSelector(_cmd));
        }
        
        NSArray *newItemNames = [NSArray arrayWithObjects:@"Apples",@"Milk",@"Bread",@"Cheese",@"Sausages",@"Butter",@"Orange Juice",@"Cereal",@"Coffee",@"Eggs",@"Tomatoes",@"Fish", nil];
        
        for (NSString *newItemName in newItemNames) {
            Item *newItem = [NSEntityDescription insertNewObjectForEntityForName:@"Item" inManagedObjectContext:_coreDataHelper.context];
            newItem.name = newItemName;
            NSLog(@"Insert New Managed Object for '%@'",newItem.name);
        }
    }
    
    别忘了导入Item.h
  • 相关阅读:
    gcvt(),ecvt(),fcvt()的区别
    SQLITE3 使用总结
    C++的类型转换浅析
    JAVA Class21
    JAVA Class20
    JAVA Class19
    JAVA Class18
    JAVA Class17
    JAVA Class16
    关于hover失效问题(!important)
  • 原文地址:https://www.cnblogs.com/SimonGao/p/4930594.html
Copyright © 2011-2022 走看看