Skip to main content

Posts

Showing posts with the label core-data

Core Data - how to generate CoreDataGeneratedAccessors?

I've gone through apple dev website, google and stack overflow to figure out the basics behind CoreDataGeneratedAccessors. I'm using Xcode 4.2 and core data. I created entities and their relationships properly including inverse. Following code is failing: self.remdetail = [NSEntityDescription insertNewObjectForEntityForName:@"RemDetail" inManagedObjectContext:context]; [rem addRemDetailObject:remdetail]; --> I'm trying to add rem detail to rem object because there are no accessor methods generated automatically, I put the following code manually in one of the NSManagedObject subclass. The following code was not generated when i created NSManagedObjects for my entities. I tried to generate accessors automatically by going through few articles and suggestions like Xcode copy & paste etc but nothing is generating the following code. in rem ManagedObject --> @interface Rem (CoreDataGeneratedAccessors) - (void)addRemDetailObject:(RemDetail *)va

NSFetchRequest for all children of a parent

How do I fetch all child entities of a parent? I have a table populated by a parent entity in Core Data. When the user touches a cell I intend to show another table with all children of that parent. How does the NSFetchRequest look like for this please? Edit: model is like this: student>>dates [one to many, one student have many days] So I want all dates for any given student (selected by touching in student table cell for that student), then populate dates table with dates for that student. Thanks!

When is it best to do an NSManagedObjectContext save?

I have noticed that for a mobile application, saving on the main thread seems to take a bit when it compares to other applications on the device. Is it recommended to only save Core Data when the application enters the background or when an application closes instead of anytime items are added and sent / received from the api?

CoreData relationships are nil after mergeChangesFromContextDidSaveNotification

Having some truly strange behavior with Core Data on iOS. I have a NSManagedObjectContext for my main thread used to read data from a SQLLite persistent store and display it to the user. I also have background processes managed by an NSOperationQueue. These background processes create an NSMangedObjectContext, fetch data from remote servers, and persist that data to the local Core Data store. I have registered for NSManagedObjectContextDidSaveNotification and when I receive those notifications call mergeChangesFromContextDidSaveNotification on the main threads NSManagedObjectContext (passing the notification object as an argument). This is all very standard and the way that all the Core Data document suggest that you deal with multi-threading. Up until recently, I have always been inserting new objects into the data store and not modifying objects in the data store. This worked fine. After a background thread writes new data, the merge occurs, I send a notification to the UIControl

Core Data - add relationship information to existing object

i set up a core data model with a "user" entity with several attributes. There's a second entity called "information". A "user" can have multiple "information" objects... A "information" allways have one "user" with these objects i initialize a tableview. the number of sections is the number of "users" the number of rows is the number of "informations" associating to a user everything fine until now. with the "user" attribute values i start several API Rest Requests (i do this in viewForHeaderInSection for every single user...). now, when im getting a successful response from the API provider with the needed results i stuck associating the result with the matching "user" entity. i created a fetchresult with predicate to get the right user - but when creating a new "information" entity and then associating the "relation property" to the fetchresult

Create a persistent store for Core Data

I did the tutorial on apples site, the Core Data tutorial for iOS and i did this tutorial about 3 times to see if i was mistaken, But when i finish the tutorial, it says that the app should work and be able to add Events to the table view, but when i press the + button, the app crashes and the console says: Cannot do save operation. There is no persistent store How could i fix this? I checked my code and i have everything!! Thanks in advance!