magicalrecord

MagicalRecord completion block is not called under test target

ⅰ亾dé卋堺 提交于 2019-12-11 03:46:30
问题 MagicalRecord.saveWithBlock({ context in if let items = dictionary["items"] as? Array<NSDictionary> { for itemInfo in items { DBItem.findOrUpdateItemWithDictionary(itemInfo, inContext: context) } } //is called if let sets = dictionary["item_sets"] as? Array<NSDictionary> { for setInfo in sets { DBSet.findOrUpdateSetWithDictionary(setInfo, inContext: context) } } }, completion: { finished, error in completionBlock(error) //is not called }) This is how I setup my core data stack: MagicalRecord

MagicalRecord: How to save imported data in background

谁说我不能喝 提交于 2019-12-10 20:17:22
问题 I'm trying to import data into Core Data and save it in a background thread with MagicalRecord . I'm basically trying to do this: __block User *user = nil; [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) { user = [User MR_findFirstOrCreateByAttribute:@"userId" withValue:userId inContext:localContext]; [user MR_importValuesForKeysWithObject:responseObject]; }]; [User setCurrentUser:user]; User is correct when I'm inside the block. After the block is completed user

Magical Record save in background

有些话、适合烂在心里 提交于 2019-12-10 13:25:08
问题 I'm using the Magical Record framework to save user settings. Now, for the first time, I want to save things in a background thread. On Magical Record's github page is an example snippet I don't fully understand: Person *person = ...; [MagicalRecord saveInBackgroundWithBlock:^(NSManagedObjectContext *localContext){ Person *localPerson = [person MR_inContext:localContext]; localPerson.firstName = @"John"; localPerson.lastName = @"Appleseed"; }]; Why is the first line needed? Can't I just

Using MagicalRecord and NSXMLParser in a background thread

耗尽温柔 提交于 2019-12-10 11:55:23
问题 I'm using an NSXMLParser to process a large and complex XML file that needs to end up in my Core Data model. To do this I am following the design pattern as discussed in the iOS book by Conway and Hillegass, where the delegate of the NSXMLParser is changed every time a new node is reached and new nodes are created on the fly. To create the entities, I am using MagicalRecord's MR_createEntity for each new node during the parsing to set up my data model. After the parsing is finished I call [

Deleting entity in MagicalRecord is not persisting

走远了吗. 提交于 2019-12-10 11:09:58
问题 I am having a strange issue with MagicalRecord. Deletes will not persist. When I delete, NSFetchedResultsControllerDelegate correctly sees that the object has been deleted. However, if I close and reopen the app, the entity reappears. The code I am using to delete the entity is: ActivityType *activityType = [_fetchedResultsController objectAtIndexPath:indexPath]; [activityType deleteInContext:[NSManagedObjectContext MR_defaultContext]]; [[NSManagedObjectContext MR_defaultContext] MR

Magical record migration failing “Can't find model for source store”

好久不见. 提交于 2019-12-10 05:23:32
问题 We made some changes to our CoreData model and looks like the auto migration is failing. Even when we set the current model to be the original model that we used to generate the data there's still the error: reason = "Can't find model for source store"; 2014-09-05 02:19:43.297[948:166846] -[LBAppDelegate application:willFinishLaunchingWithOptions:] line 132 $ WILL FINISH!! 2014-09-05 02:19:43.402[948:166846] +[LBParse ensureUserObjectExists] line 107 $ dont save 2014-09-05 02:19:52.395[948

UICollectionView with Multiple subclassed UICollectionViewCell

孤街浪徒 提交于 2019-12-09 15:37:23
问题 I have multiple sections in my UICollectionView grouped by "datasetType". I also have a custom UICollectionViewCell for each section. How can I determine which custom UICollectionViewCell I need in the cellForItemAtIndexPath method? My first though was go to based of the [sectionInfo name] : id sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:indexPath.section]; if ([[sectionInfo name] isEqualToString:@"DatasetA"]) { DatasetACell *datasetACell = [collectionView

MagicalRecord: multiple databases

坚强是说给别人听的谎言 提交于 2019-12-09 05:24:51
问题 I have an app that uses MagicalRecord, and I'm pre-populating the database with a large amount of data that is used for reference. Within that same data model, I have user-definable information pertaining to things the user may do in the app. The app was rejected because the pre-populated data is supposed to be marked as "do not backup". So, I'd like to have that data in a separate datastore so that I can keep the user data as backupable. Is there a way to have two separate datastores using

How do I use Magical Record to create & update objects and save them without using contextForCurrentThread

蓝咒 提交于 2019-12-08 17:03:37
问题 I just read the author of MagicalRecord's blog post on Why contextForCurrentThread Doesn't work in MagicalRecord. contextForCurrentThread is deprecated and saveWithBlock should be used instead because it creates a safe new NSManagedObjectContext for the relevant thread. I've been using contextForCurrentThread extensively in my app so far. However, I'm having trouble figuring out how to use saveWithBlock instead as my fetching and saving are not necessarily happening sequentially. Currently I

Importing with MagicalRecord + AFNetworking

为君一笑 提交于 2019-12-08 08:47:14
问题 I'm using AFNetworking and MagicalRecord (the current develop branch) and I'm trying to figure out how to import a lot of objects which are dependent on each other. Each resource/entity has multiple pages worth of downloads. I have a class managing the downloads for a given entity and saving them using MagicalDataImport (which has been amazing). I believe my issue is that the imports aren't happening on the same thread. So I think what is happening is: In one thread, EntityA is getting saved