Book Image

Objective C Memory Management Essentials

Book Image

Objective C Memory Management Essentials

Overview of this book

Table of Contents (18 chapters)
Objective-C Memory Management Essentials
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Creating @property


There are two ways to store data in objects, they are properties and instance variables. The latter should be used just for objects and values exclusively handled by the class itself, not from outside. Properties, on the other hand, for objects and values are accessible from outside (by other classes).

While using instance variables, you can create public or private ones. The difference is basically where you declare them as sometimes you need them to be accessible by other classes, while in other situations, there is no need to expose them to other classes. If they are declared in the header file as part of the @interface block, they have public scope and if declared in the implementation file as part of the @implementation block, they have private scope. Generally, they should be private:

@implementation Book {
  int _numberOfPages;
  int _numberOfChapters;
  NSArray *_authorsInfo;
}

To easily understand your code, instance variable starts with an underscore; it doesn't...