core-data

swift 1.2 override prepareForDeletion in NSManagedObject extension

孤者浪人 提交于 2020-01-06 15:14:59
问题 Overriding the function prepareForDeletion fails in swift 1.2 // Playground - noun: a place where people can play import UIKit import CoreData extension NSManagedObject { @objc func prepareForDeletion() { println("deleting object") } } Error: method 'prepareForDeletion()' with Objective-C selector 'prepareForDeletion' conflicts with previous declaration with the same Objective-C selector @objc func prepareForDeletion() { ^ CoreData.NSManagedObject:31:14: note: 'prepareForDeletion' previously

Why can I not get a properly formatted string from NSArray element?

╄→гoц情女王★ 提交于 2020-01-06 13:55:13
问题 I'm trying to retrieve an attribute from my core data model and put the acquired string into the title of my navigation bar. I must be doing something wrong, as I cannot set my retrieved string as the title, yet I can set the title if I manually enter the string. Here is how I am retrieving from Core Data: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Area" inManagedObjectContext:context]; [fetchRequest

Core data model, game has a winner and a loser, a player has multiple games?

断了今生、忘了曾经 提交于 2020-01-06 12:53:17
问题 I'm trying to setup my core data model. I want to have a game that has one loser and one winner. And I need a Player that has multiple games. I have the following: Entity: Player Attributes: wins, losses, name Relationships: games Destination:Game inverse: ??? winner or loser??? Entity: Game Attributes: losingScore, winningScore, Relationships: loser destination:Player Inverse:games, winner destination:Player Inverse:games How can I set this up?? Thanks! 回答1: Why not just: player.gamesWon<-

Relationships of a child entity of ManagedObject gives wrong object

て烟熏妆下的殇ゞ 提交于 2020-01-06 12:52:08
问题 To reduce redundant data I have made a parent entity of User. Both patient and Midwife are children of User. The only additional data is that a Midwife has a set of patients and a Patient can have a set of midwifes. When I am populating the managed objects to core data it shows that their relationships to the correct objects. The problem is, when I try to retrieve the object using the User class the relationship of the ManagedObject is pointing to the wrong object (it actually points to the

fetchedObjects (NSArray) count return 0 when it's full of objects

那年仲夏 提交于 2020-01-06 12:44:37
问题 I've 2 managed objects in my core data: CoreDataTrap & CoreDataAllTraps . So far, everything regarding updating, adding, deleting, saving etc with CoreDataTrap going well. But when I try to work with the 2nd managed object CoreDataAllTraps I've no error's description, just a simple nil array of fetched objects. Example for messing with CoreDataAllTraps : NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:kCORE_DATA

fetchedObjects (NSArray) count return 0 when it's full of objects

£可爱£侵袭症+ 提交于 2020-01-06 12:44:08
问题 I've 2 managed objects in my core data: CoreDataTrap & CoreDataAllTraps . So far, everything regarding updating, adding, deleting, saving etc with CoreDataTrap going well. But when I try to work with the 2nd managed object CoreDataAllTraps I've no error's description, just a simple nil array of fetched objects. Example for messing with CoreDataAllTraps : NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:kCORE_DATA

Fetching all data from an Entity and printing only displays the last record

北城余情 提交于 2020-01-06 08:39:50
问题 I'm trying to fetch all of the data from a particular Core Data Entity and place each record into a string. However the following code only prints the LAST record that it accesses. What am I doing wrong? NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Order" inManagedObjectContext:managedObjectContext]; [fetchRequest setEntity:entity]; NSArray *fetchedObjects = [managedObjectContext executeFetchRequest

iOS - Managing two CoreData models with MagicalRecord

你说的曾经没有我的故事 提交于 2020-01-06 08:39:21
问题 I'm using MagicalRecord to work with a CoreData model, which is likely to be versioned in the future. Now I need to add to my app a pre-populated database with one entity of about 80000 objects; this data is static and I'm not expected it will ever change. If I added this entity to the existing model I would need to generate a new seed db every time the model changes, increasing the project complexity. A better solution would be creating a second model, just for the new entity: the seed db

Prepopulated stored data in iOS4

巧了我就是萌 提交于 2020-01-06 08:32:25
问题 I work with iPhone iOS 4.3. In my project I need a read-only, repopulated table of data (say a table with 20 rows and 20 fields). This data has to be fetched by key on the row. What is better approach? CoreData Archives, SQLite, or other? And how can I prepare and store this table? Thank you. 回答1: I would use core data for that. Drawback: You have to write a program (Desktop or iOS) to populate the persistent store. How to use a pre-populated store, you should have a look into the Recipes

Deleting a cell in search bar table view causes delete to be executed twice

淺唱寂寞╮ 提交于 2020-01-06 08:32:14
问题 I have a table view backed up by core data with NSFetchedResultsController instance. This table has a search bar that displays filtered data. The search bar has a separate NSFetchedResultsController (FRC from now) instance. So far so good, the data is fetched and shown as expected in the table view and also shown correctly in the search bar's table view (when searching for data). My problem is that if I try to delete a cell in the search bar's table view then I get a coredata exception :