I have a string array as such:
NSArray *names;
names = [NSArray arrayWithObjects:
@"FirstList",
@"SecondList",
@"ThirdList",
nil];
I’m trying to assign an element of this string array to a string variable as such:
NSString *fileName = names[0]; // "Incompatible types in initialization"
or with casting
NSString *fileName = (NSString)names[0]; // "Conversion to non-scalar type requested"
I’m trying to do this, so I can use the string in a method that takes a string as an argument, such as:
NSString *plistPath = [bundle pathForResource:filetName ofType:@"plist"];
Is there no way to assign an element of a string array to a string variable?
You don’t use C array notation to access NSArray objects. Use the -objectAtIndex: method for your first example:
The reason for this is that NSArray is not “part of Objective-C”. It’s just a class provided by Cocoa much like any that you could write, and doesn’t get special syntax privileges.