A method of organizing code where methods and variables are organized into discrete, abstract groups called Objects. Allows humans to conceptualize interactivity easily.
Objects are created through Classes, which are blueprints for objects written in source code files.
Properties are used to provide access to class variables in other classes.
Each Objective-C object has two source code files each, one suffixed with .m and the other with .h, known as Header and Implementation files. Header files are used to declare public variables and methods to other classes, Implementation files implement the inner workings.
Two things required to create and use objects:
Declaration- the act of announcing to other objects the presence of a new variable, class, or method. Object declaration occurs in header files.
Header files contain:
In order to refer to or use an object, developer must import the header file of the object into the class its being used in. This makes the second class “aware” of the first.
Instantiation- the act of creating an object in memory from a class. The object is known as an instance of the class.
Instantiation requires two steps:
Creating an object from a class always has the same basic form:
CLASSTYPE *variable_name = [[CLASSTYPE alloc] init];
When we create a variable in Objective-C, we usually specify what kind of data it will hold, known as statically typing the data.
The asterisk (*) can be a little confusing. This is not part of the variable name. It can be placed anywhere between the data type and the variable name, so the following are all equivalent: NSString* title; NSString * title; NSString *title; Pointers are pretty much what they sound like– they “point” to a location in memory where the actual data is stored. That location in memory is the true container that holds the data.
Pointers are a part of regular C and are used because they are more efficient. When we use pointers in our programs, we only need to store and copy a simple pointer, which is really just an address for a space in memory. It’s a relatively small piece of data compared to the object itself.
Note on asterixes: all objective-c objects must be declared with the asterix as shown. Primitives and structs are not declared with an asterix.