سؤال

I use MagicalRecords but by some reason MR_SHORTHAND does not work for me.

I have added these lines below to Prefix.pch

#define MR_SHORTHAND
#import "CoreData+MagicalRecord.h"

In case when app calls + createEntity method the app terminates due unrecognized selector. But if I write MR_createEntity everything works fine.

Team *team = [Team MR_createEntity]; // This line works

but

Team *team = [Team createEntity]; // This line does not work

with reason: '+[Team createEntity]: unrecognized selector sent to class 0x74b8c'
هل كانت مفيدة؟

المحلول

I know we haven't announced it publicly prior to this answer, but we've decided to deprecate shorthand support, and remove it in the upcoming MR3 release.

Shorthand support is an interesting idea and feature, but it is not something we want to maintain. We would rather focus our efforts on getting the data centric part of MagicalRecord to be as solid and reusable as possible.

That said, you're certainly welcome to fix it yourself and submit a patch to the older branch of MagicalRecord. Some things to look at are:

  • Make sure the shorthand selectors are included, and add new ones if they are not present
  • Make sure you've used the MagicalRecord class once prior to this call. All the shorthand support is initialized in the class initializer method.
  • If you're using Cocoapods, you may need to update your pod spec reference to 'MagicalRecord/Shorthand'

نصائح أخرى

According to the official guide https://github.com/magicalpanda/MagicalRecord/blob/master/Docs/Installing-MagicalRecord.md

You have to call

[MagicalRecord enableShorthandMethods];

the above error means the core data stack is not initialized yet. you should add [MagicalRecord setupCoreDataStackWithStoreNamed:dbName]; in app delegate before [self.window makeKeyAndVisible];

because if you have called [Team createEntity]; in your root VC [self.window makeKeyAndVisible]; make the view be loaded and visible, but still app has not reached the next line to setup core data stack

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top