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.

 

posted @ 2015-11-11 21:02  yhidr  阅读(141)  评论(0编辑  收藏  举报