Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Objective-C Basics (Retired) Introduction to Objective-C From Structs to Objects


hi there ,, i am wondering what does the symbol (@) mean at the beginning of NSLog statement , and when i should use it ?

1 Answer

Typing the @ symbol in NSLog before typing a string implicitly allocates and initializes the string object. You know how creating an object usually involves typing [[ObjectType alloc] init]? Typing the @ symbol tells the compiler to automatically figure out what object type you're trying to create (in this case NSLog takes a string, so that is what you are trying to create), and then allocates and initializes that object with the value that follows.

In short, typing NSLog(@"Hi!"); is the same as typing NSLog([[NSString alloc] initWithUTF8String:"Hi!"]; The only difference is that using @ is much shorter and easier.

(In case you're wondering, the initWithUTF8String method is to initialize with a C-string, something you will be familiar with if you've used C)