magicalpanda / MagicalRecord

Super Awesome Easy Fetching for Core Data!
Other
10.8k stars 1.79k forks source link

MagicalRecord not returning NSDictionary type in fetchRequest #1114

Open Spokane-Dude opened 8 years ago

Spokane-Dude commented 8 years ago

Here is my code:

NSPredicate filter = [NSPredicate predicateWithFormat:@"aMostRecentFlag == 1"]; NSFetchRequest fetchRequest = [PreferenceData MR_requestAllWithPredicate: filter]; [fetchRequest setResultType: NSDictionaryResultType]; NSDictionary *preferenceData = [PreferenceData MR_executeFetchRequest:fetchRequest];

I get a warning from the build:

Incompatible pointer types initializing NSDictionary with an expression of type NSArray

which indicates it is NOT returning the NSDictionary as it should. And by the way, nothing is returned by the fetchRequest, although there is a record that should have been returned.

iv-mexx commented 8 years ago

which indicates it is NOT returning the NSDictionary as it should.

You are using the MR_executeFetchRequest method which has the following Signature:

+ (NSArray *) MR_executeFetchRequest:(NSFetchRequest *)request

Setting the result type to NSDictionaryResultType does not change the type of the collection thats returned, this method will always return an NSArray.

Instead, the resultType attribute of a of NSFetchRequest will change the type of objects in the collection: With NSDictionaryResultType you will get NSArray<NSDictionary *> * instead of NSArray<NSManagedObject *> *