Introduction to Cocoa Application
Development
Module 2: Creating Your First Cocoa Application
All Materials © 2008 Apple Inc. All Rights Reserved.
■ Currency Converter
- Convert US Dollars to Another Currency Based on
Exchange Rate
Exercise #1 - Create an Xcode Project
Exercise #1 Notes
■ Xcode has Templates for Many Project Types
- Cocoa, Carbon, Command Line Tools, Kernel Extension
■ Xcode Project Interface
- Groups & File List - Navigate The Files that Make Up Your
Project
- Targets - All the Products your Project Builds
- Executables - Stand Alone Executables
- Errors & Warnings - Any Build Errors or Warnings
Exercise #2 - Defining the Model
■ Declare Member Variables
■ Write Accessor Methods
- Provide Access to Get & Set Instance Variables
■ Declare & Implement Method
■ Pay Attention to Syntax
- Case Sensitive Names
- eg. myArray is not the same as MyArray
- Parenthesis and Curly Brackets must match
- Many compiler errors caused by spelling, capitalization and
punctuation mistakes
Exercise #2 Notes
■ Classes Decide Which Instance Variables They
Provide Accessors For
- Some ivars May Be Read Only
■ Accessor Nomenclature
- Getters & Setters
Exercise #3 - Define the Interface
■ Use Interface Builder to Define GUI & Object
Connections
■ Nib File
- Every Cocoa GUI application has at least one
- Loaded Automatically when Application Starts
- Menu Bar, At Least One Window, Other Objects
- Archived Objects
- “Serialized” to Disk to Maintain State
Exercise #4 - The Controller
■ Controller Provides Communication Between
Model & View
■ Outlets - An Instance Variable That Identifies An
Object
■ Declared in Your Header File with IBOutlet
Keyword
IBOutlet NSTextField *amountField;
■ Connected in Interface Builder
Exercise #4 - The Controller (ctd.)
■ Controls Send Messages to Objects via Target/
Action Connection
- Target - An Outlet To The Object That Receives Message
- Action - The Method To Invoke
- (IBAction)convert:(id)sender;
Exercise #5 - Run Application
■ Learn to use Xcode to Build and Run Your
Applic