nsmanagedobject

Is it possible to have multiple core data “databases” on one iOS app?

会有一股神秘感。 提交于 2019-11-29 08:56:51
I'm wanting to write a "management" game that utilizes Core data heavily. The game requires a pre-set, pre-defined dataset that cannot be changed by the user/system; it is used to seed the game with data and is meant to be read-only. The best example I can give is a football management game, but it could be anything. In some football management sims they give you scenarios and pre-set datasets. As the user proceeds through the game they can save/load their progress which is saved to the core data. In addition to this, the user can receive updates to the pre-defined data or can purchase

Create an NSManagedObject Without Saving? [duplicate]

人盡茶涼 提交于 2019-11-29 03:05:28
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Store But Don't Save NSManagedObject to CoreData? I need to make an NSManagedObject without saving it, how can I do this? The reason I want to do this is the app has a setup in which the user enters their details, however I only want to save the object if they complete the setup (they have the option to cancel, in which case the object needs to be discarded without being saved, which is why I don't want to

Why doesn't NSManagedObject instances hold a strong reference to their NSManagedObjectContext?

旧城冷巷雨未停 提交于 2019-11-29 02:08:25
As pointed out in another question on SO (and the Apple docs ), NSManagedObject instances do not hold a strong reference to the NSManagedObjectContext from which they originated. On first blush, this seems like a strange decision, since NSManagedObject instances are nearly useless without their context , since it leads to confusing bugs such as faults not firing when they should . Can anyone provide some background on why this is the case? Would it be dangerous to implement an NSManagedObject subclass that automatically holds a strong reference to its NSManagedObjectContext ? Edit: thanks to

Use NSManagedObject class without initWithEntity:?

时间秒杀一切 提交于 2019-11-29 02:01:03
My problem is similar to: Problem creating NSManagedObject derived class I have setup a NSManagedObject in Core Data and have a class for it. However, instead of creating an identical NSObject class, I'd like to use the NSManagedObject class, but I don't want to create the entity and save it. I just want to use it for an array, only when I need to save the object in Core Data do I want to use insertEntity: Store *store = [[Store alloc] init]; It's giving me the following error: CoreData: error: Failed to call designated initializer on NSManagedObject class 'Store' Is there a way to either

How to make a designated initializer for NSManagedObject subclass in Swift?

五迷三道 提交于 2019-11-29 00:30:29
问题 class Alternative: NSManagedObject { @NSManaged var text: String @NSManaged var isCorrect: Bool @NSManaged var image: NSData } convenience init(text: String, isCorrect: Bool, entity: NSEntityDescription, insertIntoManagedObjectContext context: NSManagedObjectContext!) { let alternative = Alternative(entity: entity, insertIntoManagedObjectContext: context) as Alternative alternative.text = text alternative.isCorrect = isCorrect return alternative } I want to make a method that lets me

Core data images from desktop to iphone

♀尐吖头ヾ 提交于 2019-11-28 18:02:41
I built a simple mac data entry tool I use with an iPhone application. I've recently added thumbnail which I added via an Image Well using simple bindings. Its a transformable data type which seems to work fine. The iPhone application however won't show the images. The attribute isn't null but I can't get an image to appear. The following is for cellForRowAtIndexPath static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault

Xcode4: Different code generated for custom core data managed objects

那年仲夏 提交于 2019-11-28 17:39:24
Now that Xcode4 is publicly available I'm moving this question out of Apple's secret dev forum: Can someone explain why the code generated in the following procedure is different than in Xcode3? Is the code better or might this be a bug? I use Core Data custom managed classes and this was the procedure I followed in Xcode3: Go to the model editor Select the entity you wish to generate source code for Go to File->New->New Files Choose managedobject class (or whatever it was, I can't open xcode3 anymore to verify) Select entities you wish to generate (the previously selected entity in step 2 is

Core Data merge two Managed Object Context

做~自己de王妃 提交于 2019-11-28 16:01:08
My Cocoa/Application has a Managed Object Context on the main thread. When I need to update my data my program will: Start a new thread Receive new data from a server Create a new Managed Object Context Send a notification to the main thread in order to merge the two context This is the function that receive the notification on the main thread - (void)loadManagedObjectFromNotification:(NSNotification *)saveNotification { if ([NSThread isMainThread]) { [self.managedObjectContext mergeChangesFromContextDidSaveNotification:saveNotification]; } else { [self performSelectorOnMainThread:@selector

core data - the primary key id of a row in the database

China☆狼群 提交于 2019-11-28 14:27:06
问题 Suppose I have a list of books stored in Core Data. I want to search for a book by it's primary key ID. I know the sqlite file created by Core Data has an ID column in each table, but this doesn't seem to be exposed to me in anyway. Does anyone have any recommendations? Thanks! 回答1: -[NSManagedObject objectID] is the unique ID for an object instance in Core Data. It can be serialized via -[NSManagedObjectID URIRepresentation] . You can retrieve the objectID from a persistent store coordinator

iPhone App floating point calculations when released to the app store.

徘徊边缘 提交于 2019-11-28 14:23:03
I released my first solo iPhone app last week that calculates 12V Marine and Boat Battery usage . I had tested it vigorously on the simulator and on my iPhone, and when I was comfortable all was well, I archived the app and released it to Apple. When users started using the app, they noted a calculation was not working as expected. The below code, which is a method on a NSManagedObject model, was producing a DIFFERENT output when released to when in debug. The below should sum up the total of the related Discharge items - but if there are no BBDischarge items, then it should return zero.