+ [NSString stringWithString:] - 什么是点? [英] +[NSString stringWithString:] -- what's the point?

查看:148
本文介绍了+ [NSString stringWithString:] - 什么是点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 NSString 字符串不可变, stringWithString:类方法的值是什么?

As NSString strings are immutable, what is the value of the stringWithString: class method?

我在使用 NSMutableString 时获得该实用程序,我没有看到该实用程序与 NSString

I get the utility when used with NSMutableString, I just didn't see the utility with the NSString class.

推荐答案

您可能有一个NSMutableString(或一些自制的NSString子类)想要复制。

You might have a NSMutableString (or some home-grown NSString subclass) that you want to duplicate.

NSMutableString *buffer = [NSMutableString string];
// do something with buffer
NSString *immutableStringToKeepAround = [NSString stringWithString:buffer];

当然,您也可以复制一份:

Of course, you can also just make a copy:

NSMutableString *buffer = [NSMutableString string];
// do something with buffer
NSString *immutableStringToKeepAround = [[buffer copy] autorelease];

但您拥有该副本,必须发布或自动发布。

but you own the copy and must release or autorelease it.

这篇关于+ [NSString stringWithString:] - 什么是点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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