iOS100

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

Quiz Time!





How does one create a new ViewController in their application?

Quiz Time!





What is an outlet?

Quiz Time!





What is an IBAction?

Quiz Time!





What is the difference between an NSArray and NSMutableArray?

Quiz Time!





What is the root class of all objects in the foundation framework?

Todays Agenda...

  • Objective-C Review
    • Objects
    • Using Instances
    • Creating Objects
    • Sending Messages
    • Destroying Objects
  • Exercise: RandomItems

Objective-C Review

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
      • OOP
      • MVC
  • 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:
      • Name
      • Date
      • List of invitees
    • It can perform actions:
      • Send an email reminder
      • Print name tags
      • Cancel the party...



Any Guesses?

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!

Using Instances

  • 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...
 Party *partyInstance;
    • 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?

Creating Objects

  • All objects have a lifespan
    • Creation
    • 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];


Sending Messages



Messages

  • Always contains three parts...
  1. Receiver - Pointer to the object being asked to execute a method
  2. Selector - The name of the method to be executed
  3. 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!

Destroying Objects

  • 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?if (venue)    [venue sendConfirmation];// Just call your method![venue sendConfirmation];




Lets Start Coding!

iOS100 - iOS Platform Development Introduction - Day 2

By Alex Rodriguez

iOS100 - iOS Platform Development Introduction - Day 2

Today we will learn about: Using Instances, Creating Objects, Sending Messages, Destroying Objects, and Complete Exercise 1: RandomItems

  • 966
Loading comments...

More from Alex Rodriguez