title: Random word From Core-data (NSString)
body: <p>I have a core-data model with a Entity called Goodie with Attribute called thingsYouWant of type String.</p>
  
  <p>i want  to pick a random word from "thingsYouWant" when u push a button, and put that in a string with format.</p>
  
  <p>but i keep getting a NSString may not respond to  objectAtIndex error ;-(</p>
  
  <p>Update: </p>
  
  <p>here is my working code:</p>
  
  <pre><code>-( void ) viewDidLoad {
  
      NSFetchRequest *request = [[NSFetchRequest alloc] init];
      [request setEntity:[NSEntityDescription
      entityForName:@"Goodie" inManagedObjectContext:
               self.managedObjectContext ]];
  
      NSError *error = nil;
      NSArray *array = [self.managedObjectContext 
                      executeFetchRequest:request error:&amp;error];
  
      if (array == nil)
      {
          // Deal with error...
      }
  
      if(array.count &gt; 0){
                int r = random()% [array count];
         goodie = [array objectAtIndex:r];
  
      } else { // no one to fetch - generate one
          goodie = [NSEntityDescription
              insertNewObjectForEntityForName:@"Goodie"
              inManagedObjectContext:self.managedObjectContext ];
      }
  
  
  
  - (void) winText {          
  
  NSArray *components = [[goodie thingsYouWant] 
                            componentsSeparatedByString:@" "];
  
  NSInteger randomIndex = (random() % [components count]);
  NSString *newWord = [components objectAtIndex:randomIndex];
  
  
  winLabel.text =[NSString stringWithFormat: @"Congratulations, 
                 the carrot you have earned is --&gt;&gt;&gt; %@", newWord];
  </code></pre>
  
  <p>}</p>
  
  <p>Thank you :-D </p>
  
  <p>Skov </p>