nsmanagedobject

Why is the extension of my Swift class not visible outside the defining file?

旧时模样 提交于 2019-12-01 02:15:07
I have an Xcode-generated NSManagedObject class for my CoreData model. @objc(SomeClass) class SomeClass : NSManagedObject { /* ... */ } It is defined in a file named 'SomeClass.swift'. I would like to extend this class, so I created 'SomeClassExtension.swift'. I define the extension like this: extension SomeClass { class func typeMethod1() {} func instanceMethod2() {} } These extension methods can be used within this defining file, but they are not visible outside of it. What is causing this issue? It sounds like your new file (SomeClassExtension.swift) didn't get included in the correct

Multiple NSEntityDescriptions Claim NSManagedObject Subclass

此生再无相见时 提交于 2019-12-01 02:08:49
I am creating a framework that allows me to use Core Data. In the framework's test target, I have configured a data model named MockModel.xcdatamodeld . It contains a single entity named MockManaged that has a single Date property. So that I can test my logic, I am creating an in-memory store. When I want to validate my saving logic, I create an instance of the in-memory store and use it. However, I keep getting the following output in the console: 2018-08-14 20:35:45.340157-0400 xctest[7529:822360] [error] warning: Multiple NSEntityDescriptions claim the NSManagedObject subclass

Multiple NSEntityDescriptions Claim NSManagedObject Subclass

放肆的年华 提交于 2019-11-30 22:21:24
问题 I am creating a framework that allows me to use Core Data. In the framework's test target, I have configured a data model named MockModel.xcdatamodeld . It contains a single entity named MockManaged that has a single Date property. So that I can test my logic, I am creating an in-memory store. When I want to validate my saving logic, I create an instance of the in-memory store and use it. However, I keep getting the following output in the console: 2018-08-14 20:35:45.340157-0400 xctest[7529

Why is the extension of my Swift class not visible outside the defining file?

可紊 提交于 2019-11-30 21:42:39
问题 I have an Xcode-generated NSManagedObject class for my CoreData model. @objc(SomeClass) class SomeClass : NSManagedObject { /* ... */ } It is defined in a file named 'SomeClass.swift'. I would like to extend this class, so I created 'SomeClassExtension.swift'. I define the extension like this: extension SomeClass { class func typeMethod1() {} func instanceMethod2() {} } These extension methods can be used within this defining file, but they are not visible outside of it. What is causing this

How to handle cleanup of external data when deleting *unsaved* Core Data objects?

谁都会走 提交于 2019-11-30 20:21:50
In a managed object i have stored a path to an image file in the application's container. When the managed object get’s deleted, the image file should be moved to trash. This should be done as late as possible, so that i can provide undo functionality for as long as possible. I was following the answers of this question: How to handle cleanup of external data when deleting Core Data objects , and was overriding -didSave in my managed object subclass to trash the files. Turns out, this works only if: the managed object has been added, the managed object context has been saved , the managed

Performing multiplication (aggregation) with CoreData: how to?

两盒软妹~` 提交于 2019-11-30 17:50:09
问题 Following a fantastic tutorial by Jeff Lamarche, I'm trying to aggregate data for a specific subclass of NSManagedObject . This is the scenario. I created a class named Product that extends NSManagedObject class. Product class has three properties like the following: @property (nonatomic, retain) NSString* name; @property (nonatomic, retain) NSNumber* quantity; @property (nonatomic, retain) NSNumber* price; I also created a category, called Product+Aggregate , where I perform a sum

Extending Core Data generated NSManagedObject classes

ε祈祈猫儿з 提交于 2019-11-30 17:23:24
问题 I've been dealing with Core Data for the first time and I wanted to know what the best practices are for extending the classes that Xcode generates for my NSManagedObject entities. I saw mogenerator and I've been also using a similar approach to that as suggested in SUPER HAPPY EASY FETCHING IN CORE DATA. So I had three kinds of classes: The EasyFetching category (only one class); A generated NSManagedObject subclass (i.e.: _Entity); A custom subclass with some custom methods like finding all

Sorting Array received from Core Data in Swift

限于喜欢 提交于 2019-11-30 16:14:07
问题 I have a NSManagedObject my own class ( BPMonitor ) for my Entity - BPMonitor : import UIKit import CoreData @objc(BPMonitor) class BPMonitor: NSManagedObject { @NSManaged var sisPress: String @NSManaged var diaPress: String @NSManaged var hbPress: String @NSManaged var datePress: NSDate } In code I receive data from Core Data to array: var results:[BPMonitor]=[] ... ... How I can sort my array for field datePress ( NSDate ) in descending order? 回答1: You just need to use standard sort or

Core data find-or-create most efficient way

点点圈 提交于 2019-11-30 12:59:40
I have around 10000 objects of entity ' Message '. When I add a new ' Message ' i want to first see whether it exists - and if it does just update it's data, but if it doesn't to create it. Right now the "find-or-create" algorithm works with by saving all of the Message objects ' objectID ' in one array and then filtering through them and getting the messages with existingObjectWithID:error: This works fine but in my case when I fetch an 'Message' using existingObjectWithID : and then try to set and save a property by setting the property of the 'Message' object and calling save: on it's

An NSManagedObjectContext cannot delete objects in other contexts

江枫思渺然 提交于 2019-11-30 11:22:29
I have two entities, each displaying on its own UITableView section. I've enabled editing to allow the user to delete rows by swiping to the right. This works fine for the first entity, but when I try to delete an object in the second entity, I get this error: An NSManagedObjectContext cannot delete objects in other contexts I get what the error says, but I can't see how it applies here. I use a retained reference to my context to create, fetch, and delete all objects from the database, so I'm sure there's only the one context. I'm also not using multiple threads. Any idea what could be