how to declare variable of NSString with double pointer

落花浮王杯 提交于 2019-12-07 02:47:13

问题


I wanna use double pointer and I tried to declare like this.

NSString **a;

but, Xcode showed me the error "Pointer to non-const type 'NSString *' with no explicit ownership" and it couldn't be compiled.

Finally I wanna do like this.

NSString **a;
NSString *b = @"b";
NSString *c = @"c";
a = &b;
*a = c;

NSLog(@"%@",b);//I wanna see "c"

Let me know any advise please.


回答1:


Change to this so that you can explicitly specify the ownership:

NSString *__strong *a;
NSString *b = @"b";
NSString *c = @"c";
a = &b;
*a = c;

NSLog(@"%@",b);//I wanna see "c"

Output:

 c

Here is the documentation on __strong.



来源:https://stackoverflow.com/questions/15146733/how-to-declare-variable-of-nsstring-with-double-pointer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!