core-data

How To Save Re-Ordered Tableview Cells To Core Data

送分小仙女□ 提交于 2020-07-10 03:51:39
问题 So I have my tableview when I re-order my rows it updates the tableview and everything but it isn't saving to core data . func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) { let appDelegate = UIApplication.shared.delegate as! AppDelegate let context = appDelegate.persistentContainer.viewContext let movedCampSites = itemName[sourceIndexPath.item] itemName.remove(at: sourceIndexPath.item) itemName.insert(movedCampSites, at:

SwiftUI TabView with List not refreshing after objected deleted from / added to Core Data

谁都会走 提交于 2020-07-08 00:34:03
问题 Description: When an object in a list (created from a fetchrequest) is deleted from a context, and the context is saved, the list does not properly update. Error: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value (Thrown on line 5 below) struct DetailView: View { @ObservedObject var event: Event var body: some View { Text("\(event.timestamp!, formatter: dateFormatter)") .navigationBarTitle(Text("Detail")) } } Steps to reproduce: Create a new Master Detail App

Is it possible to source an up-to-date snapshot from an NSFetchedResultsController

喜夏-厌秋 提交于 2020-07-07 05:59:25
问题 As of iOS 13, the easiest way to keep a UITableView in sync with a NSFetchedResultsController seems to be with snapshots. The NSFetchedResultsController vends a snapshot reference to its delegate whenever the managedObjectContext reports additions, deletions, or updates. When using snapshots ( NSDiffableDataSourceSnapshot ), there is only one FRC delegate method that needs to be implemented: controller(_:didChangeContentWith:) . In order to make that delegate method work, the

CoreData crash error Xcode 11 Beta, IOS 13 Beta

半城伤御伤魂 提交于 2020-07-04 10:11:22
问题 Im trying building my application from Xcode11 beta on phone IOS 13 Beta. I have crash when application loading. 2019-07-22 13:58:12.910460+0300 GoodWine[3738:792501] [error] fault: One or more models in this application are using transformable properties with transformer names that are either unset, or set to NSKeyedUnarchiveFromDataTransformerName. Please switch to using "NSSecureUnarchiveFromData" or a subclass of NSSecureUnarchiveFromDataTransformer instead. At some point, Core Data will

How to validate NSPredicate before calling fetch

老子叫甜甜 提交于 2020-06-29 06:13:59
问题 I create a search NSPredicate using a custom format string. Sometimes the syntax of this string is wrong and when I execute a fetch using a NSFetchRequest with this predicate I get a NSInvalidArgumentException , for example when the key-path is incorrect. I would much rather prefer to validate this predicate (call some method that returns YES if format is ok), than have an exception thrown that crashes my app. What can I do? To rephrase the inquiry into a simple question: Can I validate the

How to validate NSPredicate before calling fetch

纵饮孤独 提交于 2020-06-29 06:13:39
问题 I create a search NSPredicate using a custom format string. Sometimes the syntax of this string is wrong and when I execute a fetch using a NSFetchRequest with this predicate I get a NSInvalidArgumentException , for example when the key-path is incorrect. I would much rather prefer to validate this predicate (call some method that returns YES if format is ok), than have an exception thrown that crashes my app. What can I do? To rephrase the inquiry into a simple question: Can I validate the

Sort the Parent object based on a child element inside a NSSet of the parent object

六眼飞鱼酱① 提交于 2020-06-28 09:20:10
问题 I have a coredata object graph relationship of one to many where one Account could have many Logs (Account<->>Logs). My objective is to sort the array of Accounts that i get from the fetch request, based on the child object's value which is a date inside my Log extension Account { @NSManaged public var account_id: String? @NSManaged public var logs: NSSet? } extension SalesLogs { @NSManaged public var created_date: String? @NSManaged public var is_modified: Bool } My attempt was as bellow. I

CoreData: Get notified when NSManagedObject is changed without keeping reference to NSManagedObject

拟墨画扇 提交于 2020-06-28 03:59:53
问题 I want to observe changes of particular NSManagedObject and update UI accordingly. I don't want to keep reference to NSManagedObject because it might be removed at any time (i.e. by result of remote push notification). At the moment I'm setting up NSFetchRequest , NSFetchedResultsController and NSFetchedResultsControllerDelegate to achieve this. But want to simplify this solution (see below). Is there any simple way to observe changes in NSManagedObject without using

SwiftUI Core Data does not refresh “one to many” relations properly and lists are not refreshed

霸气de小男生 提交于 2020-06-27 03:40:52
问题 I'm trying to figure out what I can possibly be doing wrong (or, of course, misunderstood about relationships, fetches and all). In a first search, when I read the question's title, I hoped this question could help me, but I was wrong: SwiftUI TabView with List not refreshing after objected deleted from / added to Core Data Anyway... In my app, when I touch a customer item, the detail view is shown properly with its data. If I change any attribute and go back to the first view, its updated

Issue with optional Core Data relationship using NSPersistentCloudKitContainer

拥有回忆 提交于 2020-06-26 12:23:48
问题 I am using NSPersistentCloudKitContainer, not sure if that's the cause of my issue or CloudKit generic behaviour. The sync setup works fine so far. I am now adding a new feature, causing some an issue: I have an entity Item, which can be put in a Group. Relation in CD is to-one and optional. Works fine on device: I can set and remove group, everything is persisted. But CloudKit just ignores when I remove the group. It does not complain, just ignores it. No matter if remove happens from Item,