DPS923 notes – Mon Jan 13
Hands-on with Mac OS X, Xcode, and Objective-C.
.
Sorry about the limited class notes for today – I have been working non-stop since Friday to clear the start-of-semester collection of registration-related requests from students. I finished late on Sunday, so effectively had no time to post notes. My plan is to back-fill these notes later this week.
.
Topics for today
It’s our first session in a computer-lab room. Here’s what I have planned:
- Hands-on with Mac OS X
- Get familiar with Xcode, the developer tool
- Work with Objective-C and the Cocoa library of frameworks
- String-number conversions
- Introduction to collections – dictionary and array
- Introduction to iOS apps
.
Hands-on with Mac OS X
Finder, file system, WORK DRIVE, navigation
Browser(s), downloads
Cmd+Spacebar to use “Spotlight” to find and open any program or document
Cmd+Tab to switch between running programs
Using the dock and mission control
.
Get familiar with Xcode, the developer tool
From this course’s ‘Resources’ page…
Build Cmd+B, Run (with debugging) Cmd+R
Keyboard shortcuts (handout) – Cmd+0, Cmd+1, Option+Cmd+0
Show/hide debug console area – Shift+Cmd+Y
.
Work with Objective-C and the Cocoa library of frameworks
In our first class, last Thursday, we rushed through the Objective-C introduction faster than I wanted to. Today, we’ll take our time, and make sure that you can get started writing a class, and then using it.
Pure superset of C – use C when appropriate, Objective-C when necessary
Source code for a class is split over two files – interface .h (aka ‘header’), and implementation .m
When editing – toggle between .h and .m with this keyboard shortcut – Ctrl+Cmd+up-arrow
Compiler directives use the at sign – @
- @interface
- @implementation
- @end
- @property
- @ literal, for strings (and collection objects, later)
Classes contain (at least) these members
- private variables, declared in a { } code block
- declared properties – state/data for the class instance
- methods – instance or class – behaviour for the class
Declared properties for objects require memory management, e.g. (nonatomic, copy)
Method signature is dash (or plus), return type, name, with typed parameters
Become familiar with declarations, initialization, and use of
- variables
- properties
- methods
Use the NSLog statement to dump data to the debug console
- NSLog has printf-like formatting; %d for integers, %f for doubles and floats, and %@ for NSString objects
- an object’s “description” method works like .ToString()
Very brief introduction to debug tasks
- set a breakpoint, view all breakpoints, etc.
- data tip
- info
- quick look
- command-driven debug console panel/window
.
String-number conversions
We’ll create a Strings project
Work with NSString class
We’ll create a Numbers project
Will convert and round-trip strings and numbers
Using the Apple reference documentation
- Option+click for quick help (and access to the full reference document)
- Cmd+click to view the definition (i.e. where/in which module the symbol is defined)
- in a web browser, search for content using this format – “apple nsstring reference”
.
Introduction to collections – dictionary and array
Three collection classes that you’ll use often – dictionary, array, and set
We’ll use the first two many times in the next few weeks, and the set later
These are structures that have pointers to objects – they do NOT contain the objects
Immutable and mutable versions are available (the immutable version is the subclass for the mutable version)
Dictionary introduction – key-value pairs; keys are often strings, value can be ANY object
Definition, using literal syntax; dereference using objectForKey: (or valueForKey:)
If you wish to store a C scalar (e.g. int, double) as a value, you must box/wrap it, e.g. [NSNumber numberWithInt:123]
Array introduction – values can be ANY objects
Definition, using literal syntax; dereference using objectAtIndex:
Study the reference documentation for NSDictionary and NSArray
.
Introduction to iOS apps
First few projects… will use “Single View Application”
Then, for awhile we’ll use… “Empty Application”
After a few weeks, we’ll build our own ‘template’ and use that as a base
First example – study the app structure, the purpose of the ‘application delegate’, controller, and scene (view)
Round-trip data, using text field and button
Tying user interface objects to your program code
.
.
.
.
.
.
.
.
.
.
.