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

Working with classes (object orientation)

This lesson covers defining a class with @interface and @implementation in Objective-C, with the aim of understanding how object-oriented code is written.

@interface ... @end declares a class's external shape and @implementation ... @end supplies the actual work. Picture a blueprint for an animal, from which you can create as many concrete instances — a dog, a cat — as you like.

The sample code declares name and sound properties on an Animal class with @property, and assembles the sound message in a speak method. Note the doubled square brackets in [[Animal alloc] init] that create an instance.

A common early stumble is that distinctive two-part structure — declaration (@interface) separate from implementation (@implementation). If you are used to class definitions elsewhere, it takes some adjusting to.

In professional work, this @interface/@implementation structure has been the traditional design pattern of iOS development for many years.

๐Ÿ“– 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)