Would using
NSString* Test=[NSString stringWithString:@"Words"];
have any advantages over
NSString* Test=@"Words";
or is it just redundant?
Would using
NSString* Test=[NSString stringWithString:@"Words"];
have any advantages over
NSString* Test=@"Words";
or is it just redundant?
It's redundant. NSString
objects are immutable (cannot be changed) so there is no advantage that I can see over using the literal directly.
If you did the following, however:
NSMutableString *test = [NSMutableString stringWithString:@"Words"];
Then that's a different story.
Any modern ObjC compiler will warn you if you try to instantiate a string like this...
Using 'stringWithString:' with a literal is redundant
Use @"literals"
unless you actually need to "operate" on the input, á la...
NSString * w = [NSString stringWithUTF8String:"Words"];
or
NSString * join = [NSString stringWithFormat:@"con%@enate", @"cat"]