Ad space (banner)
๐ŸŽObjective-C Lessons
Lesson 3 / 68

Using variables

This lesson covers the basics of variables in Objective-C, with the aim of understanding types such as NSString and NSInteger.

A variable is like a labelled box that stores a value under a name. Text usually uses NSString and whole numbers NSInteger — types provided by the Foundation framework.

The sample code declares two variables, NSString *name = @"Alice" and NSInteger age = 14, and assembles a message with format specifiers: NSLog(@"...%@...%ld...", name, (long)age). %@ is Objective-C's own specifier for an object.

A common early stumble is forgetting the pointer *. Object types such as NSString are always handled as pointers, and leaving the * out is a compile error.

In professional work, combining C's basic types with Foundation's object types is the characteristic Objective-C style.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Objective-C directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)