Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to declare variable of NSString with double pointer

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.

like image 425
Takuya Takahashi Avatar asked Feb 28 '13 22:02

Takuya Takahashi


1 Answers

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.

like image 53
iDev Avatar answered Oct 13 '22 01:10

iDev