Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 reason?

like image 316
Jumhyn Avatar asked Feb 04 '23 00:02

Jumhyn


1 Answers

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.

like image 177
Ben Avatar answered Feb 13 '23 06:02

Ben