0

My app uses a web service in which you scan a food item which returns a UPC number. I feed this number into the web service, and i get all the details about that specific food. I grabbed the "ingredients" and turned it into an array called "ingredients".

This is the value of my array:

  ingredientsArray = dataDictionary[@"nf_ingredient_statement"];

When I NSLog my [ingredients description] value, it looks like this:

Distilled Vinegar, Water, #1 Grade Mustard Seed, Salt, Turmeric, Paprika, Spice, Natural Flavors and Garlic Powder.

My question is how can I turn that string into an array which will populate the table view?

2
  • How did you turn it into an array? Commented Aug 26, 2014 at 3:00
  • i used the web service to turn the returned value of "ingredients" into an array Commented Aug 26, 2014 at 3:01

1 Answer 1

2

IF you want to turn a comma-separated string into an array, here is how you do it, assuming the string is separated by a comma and then a space.

NSString *exampleString = @"one, two, three";
NSArray *exampleArray = [exampleString componentsSeparatedByString:@", "];

Produces:

2014-08-25 23:01:26.561 Testing[60889:3946435] (
    one,
    two,
    three
)

I'm not confident based on your post/comment if you're dealing with an array or a string, but if I were you I would NSLog(@"%@", [ingredientsArray class]); to see what class the object you think you have is.

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.