core-data

delete Single Core Data Item from a uicollectionviewCell using a button

筅森魡賤 提交于 2020-07-23 07:39:19
问题 I am trying to delete a single element of the coreData set using a button inside a collectionviewcell. So the cell has a label with the result of the core data fetch. When I hit the button it should delete the cell making it no longer appear. Also the the core data single set item should be perementley deleted. I have scence this used before in protocols but not using core data.The core data is var itemName. class CustomCell: UICollectionViewCell { @objc func delete() { }} class

delete Single Core Data Item from a uicollectionviewCell using a button

社会主义新天地 提交于 2020-07-23 07:38:46
问题 I am trying to delete a single element of the coreData set using a button inside a collectionviewcell. So the cell has a label with the result of the core data fetch. When I hit the button it should delete the cell making it no longer appear. Also the the core data single set item should be perementley deleted. I have scence this used before in protocols but not using core data.The core data is var itemName. class CustomCell: UICollectionViewCell { @objc func delete() { }} class

How to save more than one people in an Entity (CoreData)

喜夏-厌秋 提交于 2020-07-22 14:15:12
问题 I have an entity which looks like this: Entityname = Country with the attributes "city" and "person". Country *country = [NSEntityDescription insertNewObjectForEntityForName:@"Country" inManagedObjectContext:context]; country.city = @"New York"; country.person = @"Doug"; country.person = @"Carry"; country.person = @"Arthur"; I want to save more then one people in that City . I am using the code posted above, but only the last person is saved. How I can save more then one people in CoreData ?

How to: Using Combine to react to CoreData changes in the background

余生颓废 提交于 2020-07-19 05:06:43
问题 I want to achieve the following: Whenever someone triggers a CoreData save (ie. NSManagedObjectContextDidSave notification gets sent), I'd like to perform some background calculation based the changed NSManagedObject. Concrete example: Assume in a notes app, I want to asynchronously calculate the total number of words in all notes. The problem currently lies with the fact that NSManagedObject context is explicitly bound to thread and you are discouraged from using NSManagedObject s outside

How to: Using Combine to react to CoreData changes in the background

我的梦境 提交于 2020-07-19 05:03:49
问题 I want to achieve the following: Whenever someone triggers a CoreData save (ie. NSManagedObjectContextDidSave notification gets sent), I'd like to perform some background calculation based the changed NSManagedObject. Concrete example: Assume in a notes app, I want to asynchronously calculate the total number of words in all notes. The problem currently lies with the fact that NSManagedObject context is explicitly bound to thread and you are discouraged from using NSManagedObject s outside

How to: Using Combine to react to CoreData changes in the background

一世执手 提交于 2020-07-19 05:03:43
问题 I want to achieve the following: Whenever someone triggers a CoreData save (ie. NSManagedObjectContextDidSave notification gets sent), I'd like to perform some background calculation based the changed NSManagedObject. Concrete example: Assume in a notes app, I want to asynchronously calculate the total number of words in all notes. The problem currently lies with the fact that NSManagedObject context is explicitly bound to thread and you are discouraged from using NSManagedObject s outside

Reduce debug output from CoreData?

放肆的年华 提交于 2020-07-18 09:15:51
问题 I'm working on a iOS/macOS project where I'm using CoreData. It works fine, but it outputs enormous amounts of debugging info to the Console. This makes the Console unusable, since my print statements are buried in all the CoreData related stuff. I have a pretty simple CoreData setup with fetching of some data, so these are not errors, just general event logs it seems. I have the same results on other projects I have used CoreData. Any way to reduce/remove this logging to the console? Some

Share Core Data between users with NSPersistentCloudKitContainer

给你一囗甜甜゛ 提交于 2020-07-18 05:40:30
问题 Apple introduced the NSPersistentCloudKitContainer with iOS13 which enable us to use CloudKit with Core Data. I got it working pretty much instantly on different devices but my main issue is still left. Is it possible to share the data in an easy way with other users? I've been reading on CKShare but don't see how I can go from NSPersistentCloudKitContainer to that in an easy way. 回答1: There are methods on NSPersistentCloudKitContainer for accessing the underlying cloudkit records: https:/

How to store swift enum in core data?

霸气de小男生 提交于 2020-07-18 05:31:08
问题 Swift allows you to define enum but core data doesn't support (out of the box) how to save them. The recommended solution I have seen on the internet (and used thus far) is to use a private variable: class ManagedObjectSubClass : NSManagedObject { enum Cards : Int { case Diamonds, Hearts } @nsmanaged var cardRaw: Int var card : Cards { set { self.cardRaw = newValue.rawValue } get { return Cards(RawValue:cardRaw)! } } } An alternate solution is given in the answer below. 回答1: Another approach

iOS 11+ How to migrate existing Core Data to Shared App Group for use in extension?

左心房为你撑大大i 提交于 2020-07-14 04:06:06
问题 When I created an iOS 11 app using the core data template, it auto generated the following code in AppDelete.m. synthesize persistentContainer = _persistentContainer; - (NSPersistentContainer *)persistentContainer { // The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it. @synchronized (self) { if (_persistentContainer == nil) { _persistentContainer = [[NSPersistentContainer alloc] initWithName:@