Properties and Instance Variables
Understand the difference between properties and instance variables, and how to use them for data storage within objects.
Data in Your Objects
When you create objects in Objective-C, they often need to store information. Think of a Person object needing to store a name and an age.
This data is stored using either instance variables or properties. Both hold data, but they offer different levels of control and safety.
Instance Variables (IVars)
Instance variables (often called ivars) are variables declared directly within a class's interface or implementation block. They hold the actual data for an object.
- They are like direct storage slots inside your object.
- You can access them directly from within the object's methods.
- Direct access from outside the object is generally discouraged for good object-oriented practice.
All lessons in this course
- Classes, Objects, and Methods
- Properties and Instance Variables
- Protocols and Categories
- Inheritance and Method Overriding