作者zonble (zonble)
看板MacDev
标题Re: [问题] 字串前加@的意思?
时间Tue May 4 18:13:40 2010
※ 引述《iasm (魔术研究员)》之铭言:
: NSMutableString *mstr;
: mstr=[NSMutablestring stringwithstring: str1];
: [mstr insertString: @" mutable" atIndex:7];
: 最後的结果是"this is mutable string a";
: 而且实际上mstr这个mutable string其内的字串内容可以改
: 但为什麽要在 " mutable"前加代表常数的@呢
: 既然是给mutable string内容,加@就很矛盾了
: 烦请大家教教我,谢谢!!
1.mstr 是 mutable 的,所以 @" mutable" 就是 mutable?
这两件事情没有关系吧?
2.关於 @ 的意义,参见
http://tinyurl.com/24mtvg8 ,里头说
Defines a constant NSString object in the current module
and initializes the object with the specified string.
如果有 @,产生的才是 NSString 物件,如果你把 @ 拿掉,就会
变成 C 语言的 char *,加不加 @,重点不是设定成 Mutable 还是
inmutable,而是 ObjC 的字串还是 C 的字串。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.128.103.143
1F:→ uranusjr:简单来讲就是没为什麽, 只是产生 NSString object 的语法 05/05 01:46
2F:→ uranusjr:因为 " " 被 C string 用走了, 所以要改一下 05/05 01:46
3F:推 leondemon:我的看法是: @符号是Obj-C在C语言上进行物件化的标示 05/05 19:05
4F:→ leondemon:是为了让C语言成为OO的一种设计 05/05 19:06