0

I have an array, and I am trying to get an integer in my array into a int or NSInteger. It uses NSDictionaries. The following code does not work:

int color = [[records objectAtIndex:0] valueForKey: @"color"];

Note that I am using a Core Data Fetch that saves into an array called "records".

Thanks

1
  • 3
    Be specific when you say doesn't work !!!! What doesn't work. What exception it raises. Does [[records objectAtIndex:0] valueForKey: @"color"] returns string or something else which you are assigning to int. Or is records objectAtIndex:0 isn't dictionary so valueForKey: cannot be used. Commented Oct 27, 2011 at 21:30

1 Answer 1

3

Try this:

int color = [[[records objectAtIndex:0] valueForKey: @"color"] intValue];
Sign up to request clarification or add additional context in comments.

3 Comments

Then your records object is empty
@sosborn How-I have this code NSString *prize = [[records objectAtIndex:0] valueForKey: @"prize"]; and it works fine. . .
Is that code is the same location? Or is it in a different method?

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.