last day (15 days later) » 

21:54
0
Q: MagicalRecord not returning NSDictionary in fetch request

SpokaneDudeHere is my code: NSPredicate *filter = [NSPredicate predicateWithFormat:@"aMostRecentFlag == 1"]; // find old records NSFetchRequest *fetchRequest = [PreferenceData MR_requestAllWithPredicate: filter]; [fetchRequest setResultType: NSDictionaryResultType]; NSDictionary *preferenceData = [Prefe...

Where do you see it indicates a return of an NSDictionary? In NSManagedObject+MagicalRecord.h Line 23: + (NSArray *) MR_executeFetchRequest:(NSFetchRequest *)request;
I want the one (1) record that is the latest record; it contains all of the settings the user made. My problem is/was that I can't figure out how to get the data out of the array so it matches the order of the attributes in the entity... solve that and I'm one happy camper!
From what I can see you should be using + (instancetype) MR_executeFetchRequestAndReturnFirstObject:(NSFetchRequest *)request; to get just 1 result.
Not sure that would get me the correct object; that's why I use a flag which I set in the app, which is guaranteed to give me the record I need. Again, I can't figure out how to get the attributes by name because I'm concerned that they might not be in the order of the CD store.
Side note on your predicate, if you aren't using scalar values [NSPredicate predicateWithFormat:@"aMostRecentFlag == %@", [NSNumber numberWithInteger:1]];' or numberWithBool what ever your value should be.
21:54
As a rule, does CD return the attributes for an entity in the order they are listed in xcdatamodel?
Dictionaries aren't ordered so no.
This is what's now being returned after I fixed the predicate: a PFArray that looks like this:
aShopCloses = 2000;
aShopOpens = 900;
aStaffPos1 = Kellie;
aStaffPos10 = "";
aStaffPos11 = "";
aStaffPos12 = "";
aStaffPos2 = Dakota;
aStaffPos3 = Lori;

which is want I want, yes?
Yeah that looks about right.
Seems like a dictionary
yea, but it's not... let me try to use an index on the returned PFArray and see if I get the right value... brb
Screw it! I'm going to change the fetch to return the array, and hope that CD returns it in the correct order... tired of messing with this!! :={
22:11
Just add a sort in that fetch request.
Hmmm... I can't access the data that is returned from the fetch... I'm going to use MR_Findall and as I said, hope all of the attributes are in the correct order...
22:30
OK...here is what I have for code (which apparently is not correct!)
// check for most recent flag
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"aMostRecentFlag == %@", [NSNumber numberWithInteger:0]]; // find old records
// NSArray *dataReturned = [PreferenceData MR_findFirstWithPredicate:predicate inContext:defaultContext];
NSFetchRequest *fetchRequest = [PreferenceData MR_requestAllWithPredicate: predicate];
[fetchRequest setResultType: NSDictionaryResultType];
NSArray *dataReturned = [PreferenceData MR_executeFetchRequest:fetchRequest];
and here is what is being returned in dataReturned:
aStaffPos1 = Kellie;
aStaffPos10 = "";
aStaffPos11 = "";
aStaffPos12 = "";
aStaffPos2 = Dakota;
aStaffPos3 = Lori;
aStaffPos4 = "";
NOTE: the line NSLog should not end with [0,1], but rather [0];
How do I get each element out of dataReturned?
 
1 hour later…
23:50
I'll catch up with you in the morning (U.S. Pacific Time)... I have tried everything I can think of, and am unable to get the data out of dataReturned. It looks like an array of elements within a single array... I've looked all over the web and found nothing like it... I got the data into the record... now how do I get it out?

  last day (15 days later) »