具有多个实体的核心数据编辑值

时间:2016-08-08 12:04:26

标签: swift xcode core-data swift2

我是核心数据和swift的新手,我将这个多个实体放在一行,如

 let sceneObj = Scene(entity: entityDescription!,
                                           insertIntoManagedObjectContext: DbHelper .getContext())

                sceneObj.createdAt = String(dictionary!["createdAt"]!)


                let appActionsDict = dictionary!["appActions"]! as? NSArray;

                for appActionsArray in appActionsDict!{
                    let entityDescription1 =
                        NSEntityDescription.entityForName("AppActions",
                                                          inManagedObjectContext: DbHelper .getContext())

                    let AppActionsObj = AppActions(entity: entityDescription1!,
                                         insertIntoManagedObjectContext: DbHelper .getContext())

                    AppActionsObj.action = appActionsArray["action"] as! NSNumber?

                    sceneObj .addObject(AppActionsObj)
                    }

如果您看到我有“场景”实体和“AppActions”,其中“AppAction”对象被添加到“场景”对象。

这个添加部分工作正常,但我仍然坚持使用相同的编辑部分。

我已经完成了这个

 let fetchedResults = try DbHelper .getContext().executeFetchRequest(req) as! [Scene]

            if fetchedResults.count > 0 {
                for i in 0 ..< fetchedResults.count {


                    let managedObject = fetchedResults[i]

                    managedObject.setValue( String(dictionary!["createdAt"]!), forKey: "createdAt") } }

我不知道如何编辑“AppActions”。

请指导我如何编辑。

提前致谢

0 个答案:

没有答案