title: How to Return a Custom Objective-C Object from a Class Method?
body: <p>I have a set of Objective-C files in my app labeled Crop.h/Crop.m. Inside is a custom array of different vegetables from a video game - each vegetable has properties like a name, growing season, number of days to grow, etc.</p>
  
  <p>I need to write a function which loops through this array and checks each Crop name value to see if it matches with my view title (self.title). Below is an example of two crop objects:</p>
  
  <pre><code>Crop *turnip = [[Crop alloc] init];
  [turnip setName:@"Turnip"];
  [turnip setSeason:@"Spring"];
  [turnip setBagPrice:120];
  [turnip setSaleValue:60];
  [turnip setDaysToGrow:5];
  [turnip setRenewableDays:0];
  
  Crop *potato = [[Crop alloc] init];
  [potato setName:@"Potato"];
  [potato setSeason:@"Spring"];
  [potato setBagPrice:150];
  [potato setSaleValue:80];
  [potato setDaysToGrow:8];
  [potato setRenewableDays:0];
  </code></pre>
  
  <p>Then what I'm thinking is calling a new class function titled <strong>returnCropData:</strong> which takes the self.title as a parameter. I'm just not sure if this is my best method... I'd appreciate any suggestions from iOS devs.</p>
  
  <p>Here's the simple class method I have so far - no data matching yet as I'm still trying to figure out which loop would be best. I'm also struggling to figure out the syntax to add an NSString parameter onto the function</p>
  
  <pre><code>+ (Crop *)returnCropData
  {
      Crop *turnip = [[Crop alloc] init];
      [turnip setName:@"Turnip"];
      [turnip setSeason:@"Spring"];
      [turnip setBagPrice:120];
      [turnip setSaleValue:60];
      [turnip setDaysToGrow:5];
      [turnip setRenewableDays:0];
  
      // more crops here....
  
      NSMutableArray *cropListing = [[NSMutableArray alloc] init];
      [cropListing addObject:turnip];
      [cropListing addObject:potato];
      // add the other crops here...
  
      return potato; 
      // return any Crop value for now
  }
  </code></pre>