What is the replacement method for this MagicalRecord deprecated call?

后端 未结 2 1887
旧时难觅i
旧时难觅i 2020-11-29 11:20

How do I find the replacement method in MagicalRecord for this (which has been deprecated)? I have looked at Google, SO and the docs; nothing seems to be a replacement, and

2条回答
  •  天命终不由人
    2020-11-29 12:02

    casademora is correct but I'll try to be more precise because I encounter some issues when converting my

        [[NSManagedObjectContext MR_contextForCurrentThread] MR_saveToPersistentStoreWithCompletion:nil];
    

    into

        [MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext)
    

    You have to be careful to change or create your entities inside the block but it's not enough.

    To retrieve your entities you must use selection request with context too.

    MR_findFirstByAttribute:withValue
    

    is not enough and updates won't be saved. You have to use instead

    MR_findFirstByAttribute:withValue:InContext:localContext
    

    And when creating entity, it's the same

    MR_createEntity
    

    must be change to

    MR_createEntityInContext:localContext
    

    Then it works like a charm :)

提交回复
热议问题