如何用双指针声明NSString的变量

时间:2013-02-28 22:14:39

标签: ios objective-c variables automatic-ref-counting double-pointer

我想使用双指针,我试图像这样声明。

NSString **a;

但是,Xcode向我显示错误“指向非const类型'NSString *'没有明确所有权的指针”并且无法编译。

最后我想这样做。

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

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

请告诉我任何建议。

1 个答案:

答案 0 :(得分:12)

更改为此以便您可以明确指定所有权:

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

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

输出:

 c
_ptrong上的

Here is the documentation