Note that there are some explanatory texts on larger screens.

plurals
  1. POcore data fetching the information in the array objective-c
    text
    copied!<p>I'm quite new to Objective-C. I've been trying to fetch from my core data entity. The following code fetches the right row because it only returns 1 result. but when I try to <code>NSlog()</code> it to see its values what I get is:</p> <pre><code>iGym[3922:c07] ( "&lt;User: 0x8397690&gt; (entity: User; id: 0x8341580 &lt;x-coredata://114815EF-85F4-411F-925B-8479E1A94770/User/p19&gt; ; data: &lt;fault&gt;)" ) </code></pre> <p>I am used to PHP that I just do a <code>var_dump()</code> and i get all the information in the array... specially when I am expecting 16 results as this entity has 16 fields.</p> <p>Could anyone tell me how could I inspect that array? and also, most important, how do I ultimately do this: fetch the <code>Gender</code> field of the matched <code>email</code> field and assign it to a <code>NSString</code> variable.</p> <p>The query i want to do in sql is <code>SELECT Gender FROM myTable WHERE email = "something@something.com;</code></p> <pre><code>-(NSInteger*)selectedGenderMethod { NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"User" inManagedObjectContext:context]; NSFetchRequest *request = [[NSFetchRequest alloc] init]; [request setEntity:entityDesc]; request.predicate = [NSPredicate predicateWithFormat:@"email = %@",_currentUser]; NSError *error = nil; NSArray *matches = [[context executeFetchRequest:request error:&amp;error] mutableCopy]; NSString * someVar= [matches[0] objectForKey:@"email"]; NSLog(@"%@",someVar); //More to come once this is sorted return 0; } </code></pre> <p>This fetching code is happening in my <code>genderPickerViewController : UIViewController</code></p> <pre><code>NSLog(@"%@", matches[0]); </code></pre> <p>returns</p> <pre><code>&lt;User: 0x83a6b00&gt; (entity: User; id: 0x83995f0 &lt;x-coredata://114815EF-85F4-411F-925B-8479E1A94770/User/p19&gt; ; data: &lt;fault&gt;) </code></pre> <p>This is my <code>User.h</code>:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import &lt;CoreData/CoreData.h&gt; @interface User : NSManagedObject @property (nonatomic, retain) NSDate * dob; @property (nonatomic, retain) NSString * email; @property (nonatomic, retain) NSNumber * firstTime; @property (nonatomic, retain) NSString * gender; @property (nonatomic, retain) NSString * height; @property (nonatomic, retain) NSNumber * idFB; @property (nonatomic, retain) NSNumber * idUserExternal; @property (nonatomic, retain) NSNumber * idUserInternal; @property (nonatomic, retain) NSNumber * isPT; @property (nonatomic, retain) NSString * language; @property (nonatomic, retain) NSString * metricSystem; @property (nonatomic, retain) NSString * name; @property (nonatomic, retain) NSString * nickname; @property (nonatomic, retain) NSString * password; @property (nonatomic, retain) NSString * surname; @property (nonatomic, retain) NSString * weight; @end </code></pre> <p><code>User.m</code>:</p> <pre><code>@implementation User @dynamic dob; @dynamic email; @dynamic firstTime; @dynamic gender; @dynamic height; @dynamic idFB; @dynamic idUserExternal; @dynamic idUserInternal; @dynamic isPT; @dynamic language; @dynamic metricSystem; @dynamic name; @dynamic nickname; @dynamic password; @dynamic surname; @dynamic weight; @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload