Objective-C Programming

Objective-C is the programming language essential for creating applications for the iPhone, iPad, and MAC platforms.

Objective-C was created in the 1980s as an extension to ANSI C. The extensions mainly add the ability to program using object-oriented techniques which were conceptually new at the time, introduced to the programming community in the SmallTalk programming language. Many of the best features of this language found their way to languages that came later such as Java and C#.

Dave Henson is the instructor for the course. Please feel free to contact Dave by email at dhenson@certifiednetworks.com if you have any comments or questions.

Section 8 - Categories, Error Handling - 11/28/2012

In this section we cover Categories, KVO, git integration, and Error/Exception handling.

This is our last class...I hope it has been beneficial and that is has helped you get started with Objective-C.

For an in-depth discussion of some of these topics, you might pick up the excellent reference from Big Nerd Ranch, Advanced Mac OS X Programming. It is definitely not required reading, but will help give a deeper understanding at a very low level of some of the topics in the class, such as Grand Central Dispatch and Blocks.

Section 7 - Misc. Topics - 11/21/2012

In this section we cover miscellaneous topics such as command line compilation and tools installation, and the Objective-C runtime.

Homework 7: The Objective-C Runtime Environment
The goal of this lab is to become familiar with the Objective-C runtime environment. It is not necessary to understand and memorize every bit of the detailed syntax of the runtime, but instead look at it in the context of Objective-C programming to get a deeper understanding of what is happening behind the scenes.

Whenever possible, decisions about the code are left to the runtime environment, not the compiler. This is one of the features of Objective-C that really makes it unique.
  • Read the Objective-C Runtime Programming Guide at Apple.com, linked below
  • Pay careful attention to the section on Messaging, and think about how this was used to extend the ANSI-C language

Section 6 - More on blocks, GCD (Grand Central Dispatch) - 11/14/2012

In this section we reviewed the "blocks" language feature. We looked at accessing data from Internet servers using NSURLConnection, NSURLRequest and NSURL classes.

It was demonstrated how the delegate callback methods of these classes can be used to free up the main thread for user interaction.

It was also demonstrated how the Grand Central Dispatch API can be used to make blocking calls execute on a background thread, thereby freeing up the main thread for user interaction with the screen as well.
Homework 6: NSURLConnection
The goal of this lab is to become comfortable retrieving data from Internet resources. This is an extremely common task required in iPhone programming.
  • TBD

Section 5 - Protocol Review, More on Inter-Class communication, Collection Classes- 11/7/2012

In this section we reviewed Protocols and looked at NSNotification and NSNotificationCenter as a means of Inter-Class communication.

The collection Class NSArray was discussed further, and blocks were used to enumerate through an NSArray instance. Other collection classes include NSMutableArray, NSDictionary and NSMutableDictionary.

The "blocks" language feature was introduced. You can read a nice set of documentation from Apple regarding blocks here:
Working with Blocks
Homework 5: Collection classes and Inter-Class communication
The goal of this lab is to become comfortable with Collection Classes such as NSArray, to get started with the 'blocks' feature of ObjectiveC, and to work with various methods for communicating from one object to another object.
  • Create a new project in XCode using the Mac OS X/Command Line Tool template
  • Create an Objective-C class called ArrayChanger
  • Create an Objective-C class named ArrayPrinter
  • In main.m, start an infinite loop prompting for user input. When the user types in a space, call a method on ArrayChanger to reset the NSArray to a random number of NSString items, then send notification through NSDistributedNotificationCenter of the change.
  • Subscribe to the notification in ArrayPrinter. Using enumeration and blocks, print the strings in the array to the console with NSLog whenever the notification arrives.

Section 4 - Properties, Protocols and Delegation - 10/24/2012

In this section we will review memory management and ARC, then spend more time with Objective-C Classes and Methods.
Homework 4: Properties, Delegates and Protocols

  • Create a new project in XCode using the Mac OS X/Command Line Tool template
  • Implement a property using the old-style getter and setter created manually
  • Implement a delegate property in a custom class that is supported by a Protocol

Section 3 - Memory management and ARC, more on Objects Classes and Methods- 10/17/2012

In this section we will review memory management and ARC, then spend more time with Objective-C Classes and Methods.
Homework 3: Classes and methods
At the end of these exercises, you should be comfortable with the syntax to work with Classes, instances of Classes (objects), and methods.
  • Create a new project in XCode using the Mac OS X/Command Line Tool template
  • Create an Objective-C class called Car
  • Create an Objective-C class named Tire
  • Implement an NSArry of Tire objects in the Car class.
  • Override the init method of the car class to setup four generic tires in the tire array.
  • Add another init method to the car class: initializeWithTires:(NSArray *)tires;
  • Override the description method of the Car class to describe your car properties (make, model, color, etc..)
  • Use NSLog to print the Car object to the console.

Section 2 - Datatypes, program flow, conditional logic, memory management - 10/10/2012

In this section we will review last week's material and continue to look at Objective-C extensions while covering the following topics:
Datatypes - last week we took a brief look at the int datatype and how that was used for storing integral numbers in variables. We will continue to look at more built-in datatypes, and how Objective-C objects can be stored in variables.

Program flow - we will look at conditional logic and looping behavior of Objective-C.

Memory management - we will look at how to manage memory storage of Objective-C objects.
Homework 2: Datatypes and Program Flow
The purpose of this homework assignment is to gain experience with variables, conditional logic and program flow.
  • Create a new project in XCode using the Mac OS X/Command Line Tool template
  • Create an Objective-C class called MyMath
  • Exposes an instance method named Calculate which returns an int value and accepts two int values as parameters
  • Create an instance of the MyMath class in the main() method, setup three variables, and call the Calculate method if one input parameter is positive and the other is negative.
  • Print the results of the calculation to the console, or report to the console that the calculation was not performed.


Here is a video (raw and unedited) of me creating a solution to homework 2 which you can find by clicking Homework2.zip

Section 1 - Getting Started with Objective-C - 10/3/2012

In this section we will cover basic syntax elements of the Objective-C language. The language elements will be demonstrated in a variety of contexts, including command-line tools and the iPad.

Homework 1: Getting Started with XCode and Objective-C
The purpose of this homework assignment is to gain experience working with Objective-C.
  • Download and install the latest version of XCode
  • Create a new project in XCode using the Mac OS X/Command Line Tool template
  • Create both a C method and an Objective-C method in the main method of the application that print "hello world" to the console
  • Navigate to the Apple developer site, and read the Objective-C Primer linked below. This is approximately 8 pages, and gives a really nice review of the extensions you will find in Objective-C.
Apple Documentation - Objective-C, A Primer.


XCode Projects - Class Demos, Examples and Homework Answers

Slides

Course Logistics

This course meets Wednesday afternoons from 3:30pm to 6:30pm. The classroom will be open for students at 3:15pm. It meets for eight afternoons, skipping Halloween on 10/31/2012. The class runs from 10/3/2012 through 11/28/2012.

Programming-ObjectiveC-syllabus.pdf

Previous Sections of This Course

External Links

apple.com - Objective-C Runtime Programming Guide
Apple.com - Object-Oriented Programming with Objective-C
Apple.com Developer - Information about development on Apple platforms
Gnustep.org - cross platform open source Cocoa environment for Linux and Windows.
Why Learning Objective-C is Hard - Interesting perspective from a blogger.


home Site Map Terms of Use Privacy Policy Client Directories