天道酬勤,学无止境

core-data

Can't map an array of objects for NSManagedObject in RestKit

Question I have User class which is NSManagedObject subclass: @interface User : NSManagedObject @property (nonatomic, retain) NSString * about; @property (nonatomic, retain) NSString * contactAddress; @property (nonatomic, retain) NSString * contactEmail; @property (nonatomic, retain) NSString * hobbies; @property (nonatomic, retain) NSArray* jobExperience; @property (nonatomic, retain) NSString * name; @property (nonatomic, retain) NSString * surname; @end As you can see this object has an NSArray property of objects JobExperience. JobExperience defined as follows: @interface JobExperience

2021-09-24 06:26:47    分类:技术分享    ios   objective-c   cocoa-touch   core-data   restkit

CoreData getting attribute type - how to determine if it is a primitive

Question I'm trying to get all the attributes for an entity and then determine their type - I know I can do something on this line: if(![[thisAttribute attributeValueClassName] isKindOfClass:[NSString class]]) { but how do I check for a BOOL, Float or Integer? Here's my code so far: //get the attributes for this entity - we need to parse the dictionary of data we want to store and convert its contents from NSStrings to whatever type the entity requires NSEntityDescription* entity = [NSEntityDescription entityForName:strEntityName inManagedObjectContext:myMOC]; NSDictionary* dictAttributes =

2021-09-24 05:41:03    分类:技术分享    objective-c   core-data   nsentitydescription   nsattributedescription

CoreData getting attribute type - how to determine if it is a primitive

Question I'm trying to get all the attributes for an entity and then determine their type - I know I can do something on this line: if(![[thisAttribute attributeValueClassName] isKindOfClass:[NSString class]]) { but how do I check for a BOOL, Float or Integer? Here's my code so far: //get the attributes for this entity - we need to parse the dictionary of data we want to store and convert its contents from NSStrings to whatever type the entity requires NSEntityDescription* entity = [NSEntityDescription entityForName:strEntityName inManagedObjectContext:myMOC]; NSDictionary* dictAttributes =

2021-09-24 05:38:09    分类:技术分享    objective-c   core-data   nsentitydescription   nsattributedescription

Applying a filter to NSFetchedResultsController

Question The following works to display the list of "Pins" on a table and I can change _category using an actionsheet successfully. I want to only show results that match the given category (i.e. Travel), but still be able to add Pins that don't have the same category (i.e. Home) to managedObjectContext. I have tried many ways to use a predicate to filter the fetched data (by comparing _category to the 'category' property of Pin) to no avail - the furthest I've gotten still showed all of my entries regardless of category but only allowed pins of the chosen category to be added. Most of this

2021-09-24 04:13:41    分类:技术分享    objective-c   uitableview   core-data   filter   predicate

Using two different Core Data Models in the same iPhone app. How can I do it?

Question I am trying to use two different Core Data Models in a iPhone application, I created and correctly set up the first Core Data Model that uses SQLite as persistent object store. This one works very well and the pre-populated default store loads correctly in a Table View. Now I want to create a different Core Data Model with a different pre-populated SQLite default store to load it in a different Table View in the same iPhone application. How can I do this task? I read the Core Data documentation and downloaded the sample codes but I did not find anything about this task. Any sample

2021-09-23 23:28:17    分类:技术分享    iphone   core-data   data-storage

EXC_BAD_ACCESS crash when updating NSManagedObject

Question I have an application that pulls JSON data from a server, parses the data into NSManagedObject subclasses and these NSManagedObject subclasses are then used as properties in various view controllers. The trouble I'm having is that at some point in the future the data on the server will change and this will trigger an update pull request. When attempting to update the NSManagedObject subclasses, the app is crashing if the user then attempts to modify NSManagedObject via the UI by e.g. answering a question which updates a relationship on that NSManagedObject. Is it possible to use

2021-09-23 16:43:04    分类:技术分享    ios   core-data   nsmanagedobject   nsmanagedobjectcontext   nsoperation

NSFetchedResultsController index beyond bounds

Question I'm using an NSFetchedResultsController to display items in my table view: - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return [[self.fetchedResultsController fetchedObjects] count]; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"TagCell"

2021-09-23 16:16:52    分类:技术分享    iphone   cocoa-touch   uitableview   core-data   nsfetchedresultscontroller

Determining if an NSDate is today in NSPredicate

Question I've tried multiple methods and tried some suggestions on this site, but how can I determine if a CoreData attribute "dueDate" is equal to "Today", I know NSDate is a specific time as well but I want the predicate to return if it is the same day/month/year regardless of what the time is in the day. Any suggestions? Answer1 This is what I came up with: - (NSPredicate *)matchAttribute:(NSString *)attributeName withDate:(NSDate *)date { NSDateComponents *components = [[NSCalendar currentCalendar] components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:date]

2021-09-23 15:22:19    分类:技术分享    ios   objective-c   core-data   nsdate   nspredicate

Array Index Out Of Range - Error when optional unbinding

Question I have an entity called Settings with an attribute called backgroundColor of type Int, if it is 1 then the view controller will have a background of white if 0 then a background of dark grey. But I am getting the following error when trying to open the view controller; fatal error: Array Index out of range For the following line in my function if settingsArray.count == 1 { setting = settingsArray[1] } else if settingsArray.count <= 0 { println("No settings in array") } View Controller var settingsArray: [Settings]! var setting: Settings! var backgroundSetting: Bool = true override

2021-09-23 13:35:58    分类:技术分享    ios   arrays   swift   core-data   optional

Swift - Core Data Seeding Class

Question I am following the current tutorial on creating a large class to handle seeding a large database with data. http://www.andrewcbancroft.com/2015/02/25/using-swift-to-seed-a-core-data-database/ My database is populated using JSON, though I am wanting to copy the pattern the author uses in the above article. During the article he mentions this approach violates the single-use responsibility. I am aware that classes should take a single responsibility, but given a situation such as mine where I will need to seed quite a large dataset when the user logs in for example, is there another

2021-09-23 11:56:29    分类:技术分享    ios   swift   core-data