如何使用双指针声明NSString的变量 [英] how to declare variable of NSString with double pointer

查看:300
本文介绍了如何使用双指针声明NSString的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

NSString **a;

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

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

最后我想这样做。

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

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

请告诉我任何建议。

推荐答案

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

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"

输出:

 c

这里是__strong上的文档

这篇关于如何使用双指针声明NSString的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆