本文介绍了+[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:]
发布评论