Note that there are some explanatory texts on larger screens.

plurals
  1. POCoreData for Adding under an Object in Relationship
    text
    copied!<p>This is probably easier for iPhone devs who are familiar with CoreData but i am not and would really like to know how to properly access my data within a crucial deadline.</p> <p>This is what my core data is once its set to an <code>NSMutableArray</code> and pulled with NSLog</p> <pre><code>Questions List KM: ( "&lt;Question: 0x8589630&gt; (entity: Question; id: 0x8588820 &lt;x-coredata://FDC76465-4884-473A-B46A-3451BCB74F5C/Question/p1&gt; ; data: {\n orderID = 0;\n project = \"0x818e300 &lt;x-coredata://FDC76465-4884-473A-B46A-3451BCB74F5C/Project/p1&gt;\";\n question = \"What is ...? \";\n strategy = \"&lt;relationship fault: 0x8264930 'strategy'&gt;\";\n})", "&lt;Question: 0x85898d0&gt; (entity: Question; id: 0x8588830 &lt;x-coredata://FDC76465-4884-473A-B46A-3451BCB74F5C/Question/p2&gt; ; data: {\n orderID = 1;\n project = \"0x818e300 &lt;x-coredata://FDC76465-4884-473A-B46A-3451BCB74F5C/Project/p1&gt;\";\n question = \"How is ...? \";\n strategy = \"&lt;relationship fault: 0x826fa60 'strategy'&gt;\";\n})", "&lt;Question: 0x8589930&gt; (entity: Question; id: 0x8588840 &lt;x-coredata://FDC76465-4884-473A-B46A-3451BCB74F5C/Question/p3&gt; ; data: {\n orderID = 2;\n project = \"0x818e300 &lt;x-coredata://FDC76465-4884-473A-B46A-3451BCB74F5C/Project/p1&gt;\";\n question = \"Where is ...? \";\n strategy = \"&lt;relationship fault: 0x826c430 'strategy'&gt;\";\n})" ) </code></pre> <p>I was able to easily pull this to an array with the below:</p> <pre><code>// fetch and sort questions NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Question" inManagedObjectContext:self.managedObjectContext]; [request setEntity:entity]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"orderID" ascending:YES]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [request setSortDescriptors:sortDescriptors]; NSError *error = nil; NSMutableArray *mutableFetchResults = [[self.managedObjectContext executeFetchRequest:request error:&amp;error] mutableCopy]; if (mutableFetchResults == nil) { // Handle the error. NSLog(@"No Results in Questions Array."); } [self setQuestionsList:mutableFetchResults]; </code></pre> <p>Here is the Question.h or Question Definitions:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import &lt;CoreData/CoreData.h&gt; @class Project, Strategy; @interface Question : NSManagedObject @property (nonatomic, retain) NSNumber * orderID; @property (nonatomic, retain) NSString * question; @property (nonatomic, retain) Project *project; @property (nonatomic, retain) NSSet *strategy; @end @interface Question (CoreDataGeneratedAccessors) - (void)addStrategyObject:(Strategy *)value; - (void)removeStrategyObject:(Strategy *)value; - (void)addStrategy:(NSSet *)values; - (void)removeStrategy:(NSSet *)values; @end </code></pre> <p>here is Strategy.h for definitions:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import &lt;CoreData/CoreData.h&gt; @class Question; @interface Strategy : NSManagedObject @property (nonatomic, retain) NSString * strategy; @property (nonatomic, retain) Question *question; @end </code></pre> <p>You can see in the NsLog of the data that there are Three Questions</p> <ol> <li>question = \"What is ...? </li> <li>question = \"How is ...?</li> <li>question = \"Where is ...?</li> </ol> <p>It also shows that there is a Strategy Section in the Relationship:</p> <pre><code>strategy = \"&lt;relationship fault: 0x826c430 'strategy'&gt;\ </code></pre> <p>What I need to be able to do is access this Strategy and Add a single Object to it of Type NSString.</p> <p>Once assigned then i need to Pull as the Strategies to an NSMutableArray to be pushing into a UITableView.</p> <p>I know this is a lot to take in but to an Apple Guru this probably sounds like Cake and Ice Cream.</p> <p>If more Information is needed to answer, please let me know in the comments....a great StackOverflow member once told me </p> <blockquote> <p>"sometimes the hardest part is finding the right way to ask a question."</p> </blockquote> <p>Any Help is Much Appreciated!</p>
 

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