0

I've encountered a weird issue thats causing me quite the headache. I am initializing an NSArray object using initWithObjects. I'm passing in 7 objects but immediately afterwords, if I log the count of the array, I only have a count of 3. Has anyone else seen this? I've used this method countless times with no problem before and I can't see what I'm doing wrong. The code is below:

-(DMORecipe *) saveRecipe:(NSNumber *)recipeID recipeTitle:(NSString *)title recipeDescription:(NSString *)description pictureFile:(NSString *)picFile preparationTime:(NSString *)prepTime cookingTime:(NSString *)cookTime ovenTemperature:(NSString *)ovenTemp {
    NSArray *newRow = [[NSArray alloc] initWithObjects:recipeID,title, description, picFile, prepTime, cookTime, ovenTemp, nil];
    NSLog(@"Before update, the number of args is %i", [newRow count]);
}

Do I have a type-o somewhere that I'm missing? You can see I'm passing in 7 objects to the array initializer but the NSLog method shows [newRow count] = 3.

1
  • nhahtdh is right. Look at his post below. In the method initWithObjects, passing nil as a parameter signals that that is the last object passed in. On a side note, I would recommend using an NSURL instead of an NSString for your picFile parameter, as NSURLs are more efficient when storing path data. Check out this question for more info on NSURLs and NSStrings: <stackoverflow.com/questions/7769219/…> Commented Jun 2, 2012 at 4:07

1 Answer 1

2

If any of the object passed in is nil, the rest of the argument will be ignored.

In this case, it seems that picFile is nil.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.