How to append a string to NSMutableString

前端 未结 5 1738
自闭症患者
自闭症患者 2021-01-01 14:50

i\'m an absolute newbie with objective-c

with this code

NSMutableString *teststring;
[teststring appendString:@\"hey\"];
NSLog(teststring);
         


        
5条回答
  •  萌比男神i
    2021-01-01 15:34

    This line

    NSMutableString *teststring;
    

    simply establishes a pointer, but does not create anything. Instead, you need to create a new instance of NSMutableString, for example:

    NSMutableString *teststring = [[NSMutableString alloc] init];
    [teststring appendString:@"hey"];
    NSLog("%@", teststring);
    

提交回复
热议问题