object-c中@是什么意思,有什么作用

iOS 码拜 9年前 (2015-05-09) 766次浏览 0个评论
 

各位多指教

5分
@”test”
像这种???
好像是类似指标的声明
恩,放在一个字符串前面。就表示声明一个字符串吗?

引用 1 楼 cloudhsu 的回复:

@”test”
像这种???
好像是类似指标的声明

5分
引用 2 楼 loverfuping 的回复:

恩,放在一个字符串前面。就表示声明一个字符串吗?引用 1 楼 cloudhsu 的回复:
@”test”
像这种???
好像是类似指标的声明

放在一个字符串前面代表的是你这个字符串是NSString类型的。

不放的话,就代表你这个字符串是C风格的字符串。

3楼正解
建议楼主先看一下关于Objective-c的资料先
3楼正解

官方Learing Objective-C文档中的String部分有说到的
===
The NSString class provides an object wrapper for strings that has all of the advantages you would expect, including built-in memory management for storing arbitrary-length strings, support for Unicode, printf-style formatting utilities, and more. Because such strings are used commonly though, Objective-C provides a shorthand notation for creating NSString objects from constant values. To use this shorthand, all you have to do is precede a normal, double-quoted string with the @ symbol
===

地址:
http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/

10分
Objective-C是C语言的扩展,其中一项扩展就是Objective-C的字符串是NSString的对象。在C语言中,字符串就是指向以NULL字符结束的连续内存块的指针,区分C字符串常量和Objective-C字符串常量,就是看前面有没有@。如:
// C字符串
char *foo;
//NSString
NSString *bar;
foo = “this is a C string”;
bar = @”this is an NSString”;
另外,还有一种情况。
为了减少C代码和Objective-C代码之间的冲突,Objective-C的关键字都是使用@作为前缀。比如@end、@implementation、@class、@selector、@protocol、@property、@synthesize。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明object-c中@是什么意思,有什么作用
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!