-1

I'm currently working with fast enumeration variables, something that seems really simple I can't make it work.

I have this code, that it work

for (NSDictionary *story in stories){

    NSLog(@"%@", [story objectForKey:@"title"]);

}

This actually prints every single key stored in tittle. Now, I try to do this

for (NSDictionary *story in stories){

    NSLog(@"%@", [story objectForKey:@"title"]);

    NSString *titles = [story objectForKey:@"title"];

    [self.bigText setText:titles];
}

And it just print one. Why?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user3241911
  • 481
  • 6
  • 15

1 Answers1

1

Nevermind, figured it out myself.

NSMutableString *string = [[NSMutableString alloc] init];


for (NSDictionary *story in stories){

    NSLog(@"%@", [story objectForKey:@"title"]);

    [string appendString:[NSString stringWithFormat:@"%@", [story objectForKey:@"title"]]];
}

self.bigText.text = string;
user3241911
  • 481
  • 6
  • 15
  • Two things: Use modern syntax: `NSLog("%@", story[@"title"]);`. Don't needlessly use `stringWithFormat`. Just do: `[string appendString:story[@"title"]];`. BTW - if you really need a string format, use `NSMutableString appendFormat:`. No need to use `stringWithFormat:` in such a case. – rmaddy Jan 31 '14 at 18:20
  • @rmaddy I was just testing `NSLog("%@", story[@"title"]);` and xcode says "incompatible pointers types passing "char[3]" to paramater type ID – user3241911 Jan 31 '14 at 18:44
  • Oops - typo. You need `NSLog(@"%@", story[@"title"]);`. – rmaddy Jan 31 '14 at 18:47
  • I didn't see it either. Thanks – user3241911 Jan 31 '14 at 18:49