core-data

Relationship's entity's data is <fault>

一笑奈何 提交于 2020-06-17 09:44:27
问题 I have asked reference question in this link.I got answer using NSMangedObjectID.Now I have used below function to get Component entity from its componentID.As in the API response of SyncSurveyWebReadings,I only get componentId,I need to fetch Component entity & set as relationship.Now time taking issue is not there.But may be relationship is not getting set.When I print the relationship object I got, Optional<Array<SurveyReadingWeb>> ▿ some : 1 element - 0 : <GazSurvey_Dev.SurveyReadingWeb:

Is there a way to keep the sorting in core data in the time order the objects are added? [duplicate]

柔情痞子 提交于 2020-06-17 09:32:21
问题 This question already has an answer here : How to sort Core Data array based on Date Entered (1 answer) Closed 23 days ago . If I just add mocked data to coreData like this: func mockData() {´ let entity = NSEntityDescription.entity(forEntityName: "LocalDoorCoreDataObject", in: context) for i in 1...3 { var myEntity = MyCoreDataObject(entity: entity!, insertInto: context) myEntity.dName = "MOCKED NAME \(i)" } } But when I fetch the data it's not ordered 1, 2, 3, but is rather listed randomly.

How to get current CoreData item in onDelete

北慕城南 提交于 2020-06-17 06:22:24
问题 There two entities Parent and Child , which is one to many relationship. One Parent and many Child. I use EditMode to delete Child data like: @ObservedObject private var db = CoreDataDB<Child>(predicate: "parent") var body: some View { VStack { Form { Section(header: Text("Title")) { ForEach(db.loadDB(relatedTo: parent)) { child in if self.editMode == .active { ChildListCell(name: child.name, order: child.order) } else { ... } } .onDelete { indices in // how to know which child is by indices

How to sum filtered Core Data in SwiftUI?

倾然丶 夕夏残阳落幕 提交于 2020-06-16 18:37:24
问题 How to sum filtered Core Data values (using predicate) in SwiftUI app? I have 1 entity named NPTransaction . It has 5 attributes and I would like to sum values from the attribute named value (Integer 64) . Basically, it would sum up values of income in selected month (right now it's set to current Date() in the example code, but later on it will be set to whole current month). I have found similar question regarding Swift, but I cannot make this code to work in my app. Link to related

How to sum filtered Core Data in SwiftUI?

点点圈 提交于 2020-06-16 18:35:29
问题 How to sum filtered Core Data values (using predicate) in SwiftUI app? I have 1 entity named NPTransaction . It has 5 attributes and I would like to sum values from the attribute named value (Integer 64) . Basically, it would sum up values of income in selected month (right now it's set to current Date() in the example code, but later on it will be set to whole current month). I have found similar question regarding Swift, but I cannot make this code to work in my app. Link to related

Core Data: Rename Attribute without having issues with users and their current data

筅森魡賤 提交于 2020-06-16 17:33:37
问题 I just want to rename and add attribute on my table for a new version of my app and I want to keep the data if the app was already installed. Firstly I just set the options: let options = [NSMigratePersistentStoresAutomaticallyOption:true, NSInferMappingModelAutomaticallyOption:true] try coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: options) And I created a new version model, so if I rename the attributes and add another attributes to my

How fetch 10 records each time from table using coredata [closed]

倖福魔咒の 提交于 2020-06-15 19:07:21
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I want to fetch 10 records from database. once the first 10 records are fetched, next time I want another 10 record from the database using coredata. Also want to handle the condition like - After fetching some records at the end if there is less than 10 record in the table how to

How to Migrate Core Data's Data to App Group's Data

筅森魡賤 提交于 2020-06-11 11:47:53
问题 I just added App Groups to my app using this StackOverFlow post. Unfortunately since the defaultDirectoryURL is changing, I can not fetch any of the old data I made before using the App Groups directory. I know the data is still there because when I switch back to using a regular NSPersistentContainer instead of the GroupedPersistentContainer , I can get the data. How can I migrate my old data over to where I'm fetching the app group's data? Core Data code: class CoreDataManager { static let

How to Migrate Core Data's Data to App Group's Data

淺唱寂寞╮ 提交于 2020-06-11 11:46:16
问题 I just added App Groups to my app using this StackOverFlow post. Unfortunately since the defaultDirectoryURL is changing, I can not fetch any of the old data I made before using the App Groups directory. I know the data is still there because when I switch back to using a regular NSPersistentContainer instead of the GroupedPersistentContainer , I can get the data. How can I migrate my old data over to where I'm fetching the app group's data? Core Data code: class CoreDataManager { static let

NSManagedObject's hasChanges is true while changedValues is empty

我的梦境 提交于 2020-06-10 02:55:25
问题 I am trying to observe individual NSManagedObject changes on NSManagedObjectContextWillSaveNotification : - (void)managedObjectContextWillSave:(NSNotification *)notification { for (NSManagedObject * object in self.mutableObservedManagedObjects) { if (object.hasChanges) { [self managedObjectWasUpdated:object]; } } } The problem is that hasChanges is true while object.changedValues is empty, thus wrongly (?) triggering managedObjectWasUpdated: . I'm trying to understand why this is the case and