title: BAD ACCESS when trying to loop through Core Data has many
body: <p>I have a class called Interaction that more or less manages the NSManagedObject and keeps state for me in throughout the app.</p>
  
  <pre><code>// In IntroViewController
  AppDelegate *applicationDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
  
  applicationDelegate.interaction = [[Interaction alloc] init];
  [applicationDelegate.interaction createNewInteractionByCallId:[NSNumber numberWithInt:1] programId:[NSNumber numberWithInt:2] questionnaireId:[NSNumber numberWithInt:3] outletId:[NSNumber numberWithInt:4] userId:[NSNumber numberWithInt:5]];
  </code></pre>
  
  <p>So there I setup an instance of the interaction, and use the create method i have there to set up the managed object:</p>
  
  <pre><code>- (void)createNewInteractionByCallId:(NSNumber *)callId programId:(NSNumber *)programId questionnaireId:(NSNumber *)questionnaireId outletId:(NSNumber *)outletId userId:(NSNumber *)userId
  {    
      NSManagedObjectContext *context = [self getManagedContext];
  
      NSManagedObject *interaction = [NSEntityDescription insertNewObjectForEntityForName:@"Interaction" inManagedObjectContext:context];
  
      [interaction setValue:[NSDate date] forKey:@"date_started"];
      [interaction setValue:[self createGUUID] forKey:@"uuid"];
      [interaction setValue:callId forKey:@"call_id"];
      [interaction setValue:programId forKey:@"program_id"];
      [interaction setValue:questionnaireId forKey:@"questionnaire_id"];
      [interaction setValue:userId forKey:@"user_id"];
      [interaction setValue:outletId forKey:@"outlet_id"];
      [self saveRecord];
      self.managedObject = interaction;
  }
  </code></pre>
  
  <p>To describe the entities. An interaction has many answers. Answers relate to a question id on our remote server.</p>
  
  <p>So when i add an answer, i'll check for an answer by the given questionId and update it, or create a new one. This is where things are blowing up:</p>
  
  <pre><code>- (void)addAnswerFor:(NSNumber *)questionId questionType:(NSNumber *)questionType formId:(NSNumber *)formId answerText:(NSString *)answerText
  {
      NSManagedObject *answer;
  
      NSMutableSet *answers = [self getAnswers];
      NSArray *answersArray = [answers allObjects];
      for (NSManagedObject *ans in answersArray) {
          if ([ans valueForKey:@"question_id"] == questionId) {
              answer = ans;
          }
      }
      // ...
  }
  </code></pre>
  
  <p>// Get answers from the Interaction.m</p>
  
  <pre><code>- (NSMutableSet *)getAnswers
  {
      [self.managedObject mutableSetValueForKey:@"answers"];
  }
  </code></pre>
  
  <p>However i get the bad access error on the for loop line:</p>
  
  <pre><code>EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  </code></pre>
  
  <p>Do i need to initialize an empty set for the relationship?</p>