+[NSString stringWithString:]

编程入门 行业动态 更新时间:2024-10-16 23:27:37
本文介绍了+[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:]

本文发布于:2023-11-02 16:56:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552923.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NSString   stringWithString

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!