OC-Q&A

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.
原文地址:https://www.cnblogs.com/IDRI/p/4957349.html