4. Objective-C
Preprocessor
• Preprocessor directives tell the compiler to
perform specific actions prior to or during
compilation of the objective-c code. A
directive does not perform any action in the
language itself, but rather only a change in
the behavior of the compiler.
10. Pointers
• A pointer references a location in memory
• Obtaining the value stored at that location is
known as dereferencing the pointer.
• Pointers have many useful applications
11. Pointers
• An integer pointer declaration
int shoesize = 11;
int *shoesizeptr = &shoesize;
12. Pointers
• An integer pointer declaration
int shoesize = 11;
int *shoesizeptr = &shoesize;
• shoesizeptr is a memory address
13. Pointers
• An integer pointer declaration
int shoesize = 11; (integer variable)
int *shoesizeptr = &shoesize;
• * is the indirection operator
14. Pointers
• An integer pointer declaration
int shoesize = 11; (integer variable)
int *shoesizeptr = &shoesize;
• * is the indirection operator
• shoesizeptr now contains a memory address
15. Pointers
• An integer pointer declaration
int shoesize = 11; (integer variable)
int *shoesizeptr = &shoesize;
• * is the indirection operator
• shoesizeptr now contains a memory address
• the address of the value of shoesize
16. Pointers
• An integer pointer declaration
int shoesize = 11; (integer variable)
int *shoesizeptr = &shoesize;
• * is the indirection operator
• shoesizeptr now contains a memory address
• the address of the value of shoesize
• the integer value 11 is stored at the location
17. Pointers
• An integer pointer declaration
int shoesize = 11; (integer variable)
int *shoesizeptr = &shoesize;
• & is the address-of operator
18. Pointers
• An integer pointer declaration
int shoesize = 11; (integer variable)
int *shoesizeptr = &shoesize;
• & is the address-of operator
• "set the pointer to an integer, shoesizeptr, equal to the
address (location in memory) of the integer variable
shoesize"
19. Pointers
• An integer pointer declaration
int shoesize = 11; (integer variable)
int *shoesizeptr = &shoesize;
• deference the pointer
int newshoesize = *shoesizeptr;
20. Pointers
• An integer pointer declaration
int shoesize = 11; (integer variable)
int *shoesizeptr = &shoesize;
• deference the pointer
int newshoesize = *shoesizeptr;
• now the variable newshoesize is equal to 11
21. Pointers
• An integer pointer declaration
int shoesize = 11; (integer variable)
int *shoesizeptr = &shoesize;
• deference the pointer
int newshoesize = *shoesizeptr;
• now the variable newshoesize is equal to 11
• "assign the contents at location shoesizeptr to the integer variable
newshoesize"
22. Arrays
• An array is a set of ordered data items
• an array is used when the order matters
• arrays are zero indexed
• array index begins at zero, so an array
with 3 elements are indexed 0, 1, and 2
24. Object Oriented
Programming Concepts
Object-oriented programming (OOP) is a
programming paradigm that represents
concepts as "objects" that have data fields
(attributes that describe the object) and
associated procedures known as methods.
Objects, which are usually instances of classes,
are used to interact with one another to design
applications and computer programs.
32. Object Oriented
Programming Concepts
• code reuse is emphasized and enabled via
OOP
• objects are self-sufficient reusable units of
programming logic
• a class is a template for object creation
33. Object Oriented
Programming Concepts
• code reuse is emphasized and enabled via
OOP
• objects are self-sufficient reusable units of
programming logic
• a class is a template for object creation
• consist of nouns (properties) and verbs
(methods)
34. Object Oriented
Programming Concepts
In object-oriented programming, a class is a
construct that is used to define a distinct type.
The class is instantiated into instances of itself
– referred to as class instances, class
objects, instance objects or simply objects.
A class defines constituent members that
enable its instances to have state and
behavior.
35. Object Oriented
Programming Concepts
A class usually represents a noun, such as a
person, place or thing, or something
nominalized. For example, a "Car" class would
represent the properties and functionality of
cars in general. A single, particular car would
be an instance of the "Car" class, an object of
the type "Car"
37. Object Oriented
Programming Concepts
Objective-C supports the concept of
information hiding and encapsulation.
Encapsulation is the principle of controlling
access to class members (instance variables
and instance methods).
The @interface in an objective-c .h file, and the
@implementation in an objective-c .m file
serve to separate the interface of a class from
its implementation.
38. Object Oriented
Programming Concepts
Objective-C supports the concept of
inheritance - allowing sub-classes to inherit
interfaces from the classes that they are
derived from.
Inheritance enables a subclass to 'inherit' the
properties, methods (hence functionality) of
the object inherited from.
40. Object Oriented
Programming Concepts
Objective-C class properties are data field
descriptions (or fields, data members, or
attributes). These are usually field types and
names that will be associated with state
variables at program run time.
The structure defined by the class determines
the layout of the memory used by its
instances.
41. Object Oriented
Programming Concepts
Properties are accessed (read and set) via
setters and getters. This enables controlled
access to class instance data, a key tenet of
OOP encapsulation
In objective-c, properties (and their getters
and setters) are defined via @property and
@synthesize directives.
42. Object Oriented
Programming Concepts
Objective-C class methods define the
behavior of a class or its instances. Methods
are subroutines with the ability to alter the
state of an object or simply provide ways of
accessing it.
46. Object Oriented
Programming Concepts
• Objective-C class method definitions begin
with a plus (+)
+ (id)alloc;
• Objective-C instance method definitions
begin with a minus (-)
- (void)printTemperature;
48. Credits
• Wikipedia
• Programming in Objective-C by Stephen
Kochan
• Programming in C by Stephen Kochan
(any errors or omissions are probably mine)