nsmanagedobject

Is it possible to have Core Data sort the “many” part of a To-Many relationship during a fetch request?

自闭症网瘾萝莉.ら 提交于 2019-12-22 17:59:32
问题 I'm using Core Data to cache a decent amount of information, and I have a To-Many relationship set up among my managed objects. Naturally I use an NSFetchRequest to fetch an array of the singular side of that relationship. However, I populate a UITableView using the the "many" side of the relationship, and I'd like it to be sorted alphabetically when I pull the data. If I'm not being clear, here's an example: "employee" and "boss" are both NSManagedObjects in a To-Many relationship - each

managedObjectModel is nil (Cannot create an NSPersistentStoreCoordinator with a nil model)

那年仲夏 提交于 2019-12-22 15:25:12
问题 I have this special case scenario, where in my app works perfectly fine for some time and crashes inconsistently after some time. The error that i get during the crash is "Cannot create an NSPersistentStoreCoordinator with a nil model" . I tried debugging my app and found that the managedObjectModel is returning NULL sometimes. To add fuel to the fire, this scenario is not at all consistent. For some time the managedObjectModel is fine. But, suddenly it returns NULL ... Here is the code that

Swift dynamicCast error while inserting new object to database

一世执手 提交于 2019-12-22 12:46:15
问题 I have a dictionary which I have all data that I want to insert into database as new object. The problem is when I try to cast the newly created object it gives me exception in: libswift_stdlib_core.dylib`swift_dynamicCast: part of assembly code. The code that i am using is like this: var group:Group if (array.count == 0) { group = NSEntityDescription.insertNewObjectForEntityForName("Group", inManagedObjectContext:appDelegate.managedObjectContext) as Group } and the structure of Group class

Core Data NSManagedObject - tracking if attribute was changed

依然范特西╮ 提交于 2019-12-22 10:49:56
问题 I have an object - Config . I want to know if the Account attribute on Config has changed. When this happens, I want to send a NSNotification so that all code that cares about when the Account changes will know. My initial thought was in my NSManagedObject subclass that I would override the setAccount method to set a transient attribute AccountDidChange to true . Then in didSave if AccountDidChange was true I would send the notification and then set it back to false . Is there a better way?

Using property observers on NSManaged vars

烂漫一生 提交于 2019-12-22 01:52:46
问题 I have a var declared in a class like so: @NSManaged var isFavorite: Bool I would like to declare a property observer, very similar to the one below. var organization: String { didSet { postNotificationWithName( "newData" ) } } However, Swift tells me that having property observers on NSManaged vars is not allowed. Is there any way I can implement such a feature or something similar for my isFavorite variable? 回答1: Yes-- delete the @NSManaged . It's not absolutely required, but if you delete

RestKit: how to remove core data entries to keep the content in sync with the server?

旧街凉风 提交于 2019-12-21 13:35:30
问题 I'm using the RestKit RKObjectManager to get data from my server and store in core data (see my other post) I want to configure the deletion behavior of the old entries left in the database. I saw there's a deletionPredicate property in the RKEntityMapping class but I understand that it is used only when the service actually returns the objects to be deleted flagged as 'to-be-deleted'. (am I right?) In my case when some objects have to be deleted, they're just NOT returned by the server and I

How to do perfect KVO for NSManagedObject?

风格不统一 提交于 2019-12-21 12:33:21
问题 Perfect KVO here includes two parts: add observer correctly and remove observer correctly. The story: I use one UITableViewCell(cell) to display one NSManagedObject(object). Each object has some dynamic properties that need observing by its cell. Not all objects have the same set of observed properties. I add key path observers selectively like this: if (object.thumbnail_pic_url) [object addObserver:cell forKeyPath:@"thumbnail_picture" options:0 context:NULL]; Object could be deleted. I must

NSUndoManager, Core Data and selective undo/redo

核能气质少年 提交于 2019-12-21 10:46:11
问题 I'm working on a core data application that has a rather large hierarchy of managed objects similar to a tree. When a base object is created, it creates a few child objects which in turn create their own child objects and so on. Each of these child objects may gather information using NSURLConnections. Now, I'd like to support undo/redo with the undoManager in the managedObjectContext. The problem is, if a user creates a base object, then tries to undo that action, the base object is not

How to insert new data to entity in Swift3?

删除回忆录丶 提交于 2019-12-21 09:17:10
问题 In swift previously, I was able to use a code like this to add new data to my "TestEntity" in my data model. NSManagedObject was created for my "TestEntity" and I was able to set its attributes with the "dot" syntax At the end, I would save the context let entity=NSEntityDescription.insertNewObject(forEntityName: "TestEntity", into: context) as! TestEntity entity.testAttribute="test value" context.save() This code does not work in Swift3. When I run it, i get the following runtime error:

Core Data saving problem: can't update transformable attribute (NSArray)

孤者浪人 提交于 2019-12-21 05:21:23
问题 I have a strange problem in my Core Data app. I have three entities in my app, but today I found a problem with one of them. My problematic entity is called Invoice and it has many attributes, including Products . It's encoded NSArray of NSDictionaries (via default NSValueTransformer). Everything works fine - i create my invoice, its client, its products, etc. Everything works. But , when I choose my invoice from a list and then try to edit its products and click 'Save' button, my save works