Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Danneman101

macrumors 6502
Original poster
Aug 14, 2008
361
1
No matter how much I meddle with the syntax, I cant seem to cast an item in a NSArray to a NSString.

This is the code that makes the NSArray, by dividing up a string by a separator:
Code:
NSString *list = @"Norman, Stanley, Fletcher";
NSArray *listItems = [list componentsSeparatedByString:@", "];

So, shouldnt it be an easy thing to extract, for instance, the first name to a new string?

Code:
NSString *singleName = [listItems objectAtIndex:0];

But it wont work, so Im guessing Im missing some sort of cast, or some other piece of syntax is wrong?
 

Danneman101

macrumors 6502
Original poster
Aug 14, 2008
361
1
I get no warnings, but the app crashes and this line in main seem to be the culprit:

Code:
int retVal = UIApplicationMain(argc, argv, nil, nil);
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
But it wont work, so Im guessing Im missing some sort of cast, or some other piece of syntax is wrong?
You're not missing any sort of cast and your syntax looks correct.

Try setting a breakpoint at this line:
Code:
NSString *singleName =[listItems objectAtIndex:0];
When you run it, if the debugger stops at this line but then the app crashes when you step over that line, you know that line is somehow the culprit. If, however, the app crashes before or sometime after it breaks at that line, then there is something else causing the crash.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.