iOS Platform Development Introduction
Day 2 & 3
In the last class we learned...
How to setup an iOS project
How to create a ViewController & View (Storyboard)
How to setup up and configuring view objects
How to setup and connect outlets
How to setup and connect actions
- Created model objects using NSArrays
How does one create a new ViewController in their application?
What is an outlet?
What is an IBAction?
What is the difference between an NSArray and NSMutableArray?
What is the root class of all objects in the foundation framework?
- Objective-C Review
- Using Instances
- Creating Objects
- Sending Messages
- Destroying Objects
- Exercise: RandomItems
What is it?
- Programing language used to write iOS apps and Cocoa Touch frameworks.
- It is an extension of the lower level C programming language.
- It adds layers of abstraction
- Apple provides us w/ prebuilt and optimized collections of Objective-C classes known as the Cocoa Touch frameworks.
Lets have a party!
- How can we represent something like a party in Objective-C?
- It has unique attributes:
- List of invitees
- It can perform actions:
- Send an email reminder
- Print name tags
- Cancel the party...
HINT: Who doesn't like to party!?
Wouldn't it be nice if we could have multiple party's without having to do duplicate work?
We should use a Class!
Cookie cutter for any party...
Each instance can have it's own data...
Easy to update and maintain!
- Requires creation of a pointer variable
- A pointer stores a location in memory
- Not the object itself...
A variable that points to a Party object is declared like this...
- Creating this pointer does not create a Party object
- Only creates a variable that points to an object.
What happens if we try to use a pointer that has no object assigned to it yet?
- All objects have a lifespan
- Implementation (sent messages)
- Destroyed when it is no longer needed
- To create an object, you send it an "alloc" message
- This gives your pointer a memory address for the newly created object
Party *partyInstance = [Party alloc];
What happens when we try to use a pointer that has an object that has been allocated?
Creating Objects Continued...
- We create pointers to instances so we can send messages to them...
- The 1st message you always send to a newly allocated instance is and initialization message
- "alloc" creates and instance of our class, but its not ready to use until we "init" it.
- We usually do this in a "1 liner" called a nested message send.
Party *partyInstance = [[Party alloc] init];
Always contains three parts...
- Receiver - Pointer to the object being asked to execute a method
- Selector - The name of the method to be executed
- Arguments - The values to be supplied as the parameters to the method.
[partyInstance addAttendee:somePerson]; [partyInstance addAttendee:somePerson withDish:deviledEggs];
- These are two distinct methods that do not share any code!
With ARC you can just set your main object to nil.
partyInstance = nil;
- ARC will take care of releasing the object and all of the other objects it owns.
- In Objective-C you do not have to check for nil!
// Is value non-nil?
// Just call your method!
Lets Start Coding!
iOS100 - iOS Platform Development Introduction - Day 2
By Alex Rodriguez