How to declare a string in Objective-C?

A C string is just like in C.

char myCString[] = "test";

An NSString uses the @ character:

NSString *myNSString = @"test";

If you need to manage the NSString’s memory:

NSString *myNSString = [NSString stringWithFormat:@"test"];
NSString *myRetainedNSString = [[NSString alloc] initWithFormat:@"test"];

Or if you need an editable string:

NSMutableString *myMutableString = [NSMutableString stringWithFormat:@"test"];

You can read more from the Apple NSString documentation.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)