Whats the difference(,adv/disadv) in the two ways of initialing a string variable in ios?
NSString *var = @"value" and NSString *var =[ [NSString alloc] initWithString:@"value"]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The code:
Creates an instance of
NSCFConstantStringwhich is created by the compiler and stored as part of the program’s data. It doesn’t respond toretainorreleaseand can effectively be ignored for memory management purposes.However the code:
Allocates an
NSStringobject and initialises it with the content of the constant string@"value". It must bereleased when no longer required but cannot be updated (it is immutable), so offers little over the first piece of code.