core-data

Core Data lightweight migration crashes after App update

谁说胖子不能爱 提交于 2020-02-03 11:40:07
问题 Two days ago I released the App. According to feedback on AppStore and crash reports from itunesconnect there are a lot of crashes on launch. But not 100% users suffered, only 30% maybe. I've read the crash logs and saw a problem. It's crashing on DB migration process. I use lightweight migration of database. Usually I add new datamodel version very carefully. Even before each release I install a previous version of the App, use it for some time and only then I install the latest version

iOS: Can't compile CoreData model because of Fetched Indexes in Xcode 9

只愿长相守 提交于 2020-02-03 04:33:29
问题 According to the release notes, Xcode 9 adds support for fetched indexes: "The data model editor presents a unified interface for Core Data’s new fetch indexes feature as well as its existing property index and entity compound index features. Older data models are translated into fetch index form for editing, and saved to the old file format when necessary. Compiling a data model with a Deployment Target lower than iOS 11, watchOS 4, macOS 10.13, or tvOS 11 continues to generate a compatible

Sum of (double) fetch request field

穿精又带淫゛_ 提交于 2020-02-03 03:12:25
问题 Is it possible to get the sum of a core data (through a fetch request) field (double) in Swift UI? Thanks in advance. 回答1: Yes, you could use the reduce method. var sum: Double { fetchRequest.reduce(0) { $0 + $1.number } } This starts with an initial value of 0, and for each item in the FetchRequest, it adds the number property to the accumulated total. Assuming you have an entity called SomeEntity in your .xcdatamodeld file, with an attribute called number , the whole code might look like

Swift 2.0 Core Data - TableView not reading NSManagedObject

坚强是说给别人听的谎言 提交于 2020-02-02 16:02:34
问题 In first view controller i saved data in core data with uitextfields, i wanted to tableview to read that data in second view controller, i got no errors but i got no display of data in tableview cells. In first VC i made a property of NSManaged object, and in second VC i retrieve that object, put it in tableview but no data is displayed. This is crucial to my understanding about how tableview can read data from core data, thank you a lot. First VC import UIKit import CoreData class

Swift 2.0 Core Data - TableView not reading NSManagedObject

白昼怎懂夜的黑 提交于 2020-02-02 16:01:09
问题 In first view controller i saved data in core data with uitextfields, i wanted to tableview to read that data in second view controller, i got no errors but i got no display of data in tableview cells. In first VC i made a property of NSManaged object, and in second VC i retrieve that object, put it in tableview but no data is displayed. This is crucial to my understanding about how tableview can read data from core data, thank you a lot. First VC import UIKit import CoreData class

Core Data: Abstract entities and inheritance relationships

空扰寡人 提交于 2020-02-02 10:27:40
问题 My exact model is complicated to explain, so say that I'm modeling fruits and their seeds in Xcode's Core Data modeler. Here's some "pseudo Core Data code": abstractEntity Fruit attribute sweetness relationship Seed abstractEntity Seed attribute shape concreteEntity Apple inherits Fruit concreteEntity Orange inherits Fruit concreteEntity AppleSeed inherits Seed concreteEntity OrangeSeed inherits Seed The reason I modeled in this way is that I want to be able to fetch a mix of fruits and sort

Identifying old and new values on changed objects with NSManagedObjectContextWillSaveNotification

两盒软妹~` 提交于 2020-02-02 04:41:26
问题 I am trying to track changes to objects in a core data context, tracking the name of properties that have changed along with the old and new values. I've registered for NSManagedObjectContextWillSaveNotification to receive a notification when a save is about to occur, and can pull out the inserted/updated/deleted objects from the context... I can then see the changed values using .changedValues. However, I am having difficulties retrieving the old values... As an example, I have an object

Unrecognized selector for NSManagedObject base class

馋奶兔 提交于 2020-02-01 08:35:06
问题 I am getting an 'unrecognised selector' exception when calling a base-class method on an instance and can't see what the problem is. I have an object called Form as follows: #import <Foundation/Foundation.h> #import <CoreData/CoreData.h> #import "HPSDbBase.h" @interface Form : HPSDbBase @end The base class for Form looks like this: #import <CoreData/CoreData.h> @interface HPSDbBase : NSManagedObject @property (nonatomic, retain) NSString * id; @property (nonatomic, retain) NSString * json; -

CoreData - Duplicate existing object

为君一笑 提交于 2020-01-31 06:00:01
问题 Hi would like to duplicate an object from my core data db. Right now I'm using movement2 = [NSEntityDescription insertNewObjectForEntityForName:@"Movement" inManagedObjectContext:self.managedObjectContext]; movement2.name = movement.name; movement2.value = movement.value; movement2.date = movement.date; ... and it works. but... Is there any way to copy all the values of movement to movement2 , in one line of code? 回答1: NSManagedObject, unlike NSObject, provides an API to iterate over its

CoreData - Duplicate existing object

烂漫一生 提交于 2020-01-31 05:58:14
问题 Hi would like to duplicate an object from my core data db. Right now I'm using movement2 = [NSEntityDescription insertNewObjectForEntityForName:@"Movement" inManagedObjectContext:self.managedObjectContext]; movement2.name = movement.name; movement2.value = movement.value; movement2.date = movement.date; ... and it works. but... Is there any way to copy all the values of movement to movement2 , in one line of code? 回答1: NSManagedObject, unlike NSObject, provides an API to iterate over its