开发者

Purpose of @ Symbol Before Strings?

I've been using Objective-C for a while now, but have never really understood what the purpose of the @ symbol before all strings is. For instance, why do you have to declare a string like this:

NSString *string = @"This is a string";

and not like this:

NSString *anotherString = "This is another string";

as you do in Java or so many other programming languages. Is there a good r开发者_JAVA技巧eason?


It denotes a NSString (rather than a standard C string)

an NSString is an Object that stores a unicode string and provides a bunch of method to assist with manipulating.

a C string is just a \0 terminated bunch of characters (bytes).

EDIT: and the good reason is that Objective-C builds on top of C, the C language constructs need to be still available. @"" is an objective-c only extension.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜