objective c - stringByAppendingString on same object -
I have a question on NSString
, so the question is:
NSString str = @ "Hello"; Str = [str stringByAppendingString: @ "world"];
If we get NSLog
to str
we will get an output - HelloWorld
str
is NSString
class variable one can not be changed after its one constant (which has been defined) ) So how can we change it, (note that I have used the same NSString
object str
).
You have not declared the string as static, but NSString
It is irreversible that you are creating a new string and replacing str
is an unstable type in many OBJ-C classes, so if you want to modify this string as an example, So you want something else:
NSMutableString * str = [NSMutableString stringWithString: @ "Hello"]; [Stradded string: @ "world"];
Note, @ "Hello" is a NSString
, so by trying to start a NSMutableString
using that syntax An error will occur
Comments
Post a Comment