iPhone and iPad SDK Programming Class

Programming the Apple iPhone and iPad devices using the IOS SDK can be challenging for beginners, but rewarding. This class covers a broad overview of iPhone and iPad programming, including a coverage of Objective-C, UIKit framework, and other frameworks needed for successful completion of iOS projects.


Lecture 11 - CoreMotion, MapKit, Over the Air (OTA) Deployment - 12/19/2012

In this lecture we cover device hardware: Compass, Accelerometer, Gyro. Core Location and the Core Motion API are covered. Example_Location.zip demonstrates passing location data from Core Location to the google maps website as part of the query string.

Writing applications using HTML 5, css and Javascript is covered.

HTMLDemo.zip is a project that demonstrates loading an html file locally from the application bundle. The local html file references a local javascript file, calling an annoying javascript popup.

Here are some interesting links related to authoring and integrating HTML into your application:

JSBridge to Cocoa links javascript to Cocoa objects
genwi.com offers an HTML5 cms authoring service
HTML5 game tutorial from Six Revisions - very interesting coverage of HTML5 features
Phone Gap is an open source mobile dev platform
Bright Cove App cloud is another HTML5 app hosting service
Appcelerator is another HTML5 app hosting service with free trial


In class, we will attempt to demonstrate an OTA deployment - providing a downloadable link for installing an app for testing.


Homework 11: GPS

Write an application that displays the raw GPS data onto the screen. Optionally, use the MapKit API to display your current location on a map.

Lecture 10 - Network connections with sockets and GameKit - 12/12/2012

In this lecture we cover networking with sockets in the iOS environment, looking at a third-party library at which helps wrap the sockets classes. The GameKit classes will also be covered.

NodeJS - Host javascript socket servers
CocoaAsyncSocket - open source sockets library
Arduino - open source hardware device
CGNetwork Programming Guide


Homework 10: Sockets and GameKit

Option 1: Write an application that communicates with another device over GameKit. When you type a message into a UITextField, that message should be displayed on the screen of the other device. Display all text that comes across from GameKit in upper case.

Option 2: Write an application that communicates through a socket to Node.js running on your mac. Anything that is typed into a UITextField should be displayed onto the screen of any other device connected to the same socket.

Lecture 9 - Asynchronous Downloads - NSURLConnection Delegate, Grand Central Dispatch (GCD) - 12/5/2012

This session we will look at pulling data from web servers in an asynchronous/non-blocking manner using NSURLConnection and it's delegate methods and through GCD.

Along the way, we will create a nice little helper class called AsyncString which takes care of the downloading for us.




Homework 9: Web Services
  • Create an iphone app with a UITableView
  • Using this url: slowitems.aspx?DelayMS=200 download the data using blocking code
  • Repeat the exercise using NSURLConnection Delegate
  • Repeat the exercise using GCD
  • Repeat the exercise using a helper class that takes care of the hard work for you
  • Bonus:Rework homework 8 using the asynchronous technique from this lecture


Lecture 8 - Files, JSON, XML and Web Services - 11/28/2012

In this lecture, we cover storing data in the Documents directory, parsing XML and JSON files, and pulling XML and JSON data from web servers in a synchronous/blocking manner. Next week, we will continue this discussion by making web calls asynchronously through an API called Grand Central Dispatch.


Homework 8: File Parsing and Web Services
Create an ipad application that parses the XML feed that we create during class to into an array that supports a UITableView. When an item is selected from the UITableView, send that item as a parameter to the web service and parse the resulting JSON for a detailed view.


Products XML feed: http://54.245.50.38/products.xml

Product JSON feed: http://54.245.50.38/productJson.php?id=1



Lecture 7 - Animation - 11/21/2012

In this lecture, we covered various animation techniques: UIImageView imageArray, NSTimer based movements and affine transforms, UIView block based animation.

CALayer is a class that is wrapped by UIView, and is important in providing smooth hardware-accelerated animation.

Core Animation Programming Guide at apple.com is a great reference. You might also check out Ray Wenderlich's CALayer Tutorial

iOSDay7Demo1.zip and iOSDay7AnimationTimer.zip and demonstrate various animation techniques.




Homework 7: Core Animation
Extend homework 6 (custom views) by making each view spin in a circle when it is touched. You might accomplish this with an NSTimer in combination with either the UIView.transform property or by applying a CGAffineTransform in drawRect(). You could also try UIView animation blocks...to get a full circle, you may need to apply two blocks.


Lecture 6 - Custom View Drawing - 11/14/2012

In this lecture, we look at the drawRect method of a custom UIView.

We will use Core Graphics C library to draw custom shapes into the UIView. Sometimes people refer to the Core Graphics API with the name Quartz or Quartz 2D.

See the Quartz 2D Programming Guide at apple.com for more in depth information about working with Core Graphics.

Homework 6: Custom View Drawing
In this lab, you will investigate drawing custom UIView objects with Core Graphics. Many of the more creative iphone and ipad applications use this technique to create a unique and dynamic user interface.
  • Create an ipad application using the view-based template
  • Implement a custom UIView class name PolyGon with a property named numberOfSides
  • Using the .frame.size property, draw the polygon with a line size of 4 points
  • Derive a class named Square from the PolyGon class, and override the setter for the numberOfSides property to make it read-only
  • Draw four instances of the PolyGon class on the screen in random positions of random sizes and shapes
  • Draw one instance of the Square class on the screen in a random position and size
  • Change the position and size of the objects on the screen in the touchesBegan event of the UIViewController
  • Bonus points:implement a lineColor property and a fillColor property




Lecture 5 - Controllers of UIViewControllers - 11/7/2012

In this lecture, we looked mainly at the UITabBarController.


Homework 5: UITabBarController
In this lab, you will investigate UITabBarController, which contains an array of UIViewControllers. The UITabBarController manages the display of the .view property of each UIViewController.
  • Create an iphone or ipad application using the view-based template. In ViewDidLoad, Implement 3 UIViewControllers and add them to a UITabBarController. Place the UITabBarController.view onto the screen.
  • In the first tab, implement a UINavigationContoller that holds a UITableView. Slide in a detail screen when a row is clicked.
  • On the second tab, display a scrollable UIImageView with a world map that is larger than the physical screen on the device.
  • On the third tab, display a UIWebView implemented as the .view property of a custom UIViewController


Watch the movie "What about Bob" to learn about "baby steps" from Bill Murray.

Take baby steps by creating simple apps implementing the custom UIViewController required for each tab. Only plug them into the tab application after it the UIViewController is complete and working properly. For example, make a simple view-based app with a scrollable image. After it is working properly, drop that view controller into the final tab based application.

Don't forget to investigate the UIScrollViewDelegate and the UITabBarDelegate protocols. For bonus points, implement a method or two from the delegate protocols.


Lecture 4 - Delegation and Protocols - 10/24/2012

In this lecture, we review the UITableView which is so re-usable because of it's effective use of the delegation pattern.

A Protocol is a list of methods (Interface) that is formally defined. A protocol can be adopted by a class by using the less-than and greater-than symbols <>. For example to adopt the UITableViewDelegate Protocol:

@interface MyCustomVC : UIViewController <UITableViewDelegate>

The compiler can then check the class implementation for the required methods and error out if any methods are missing. Protocols are heavily used in the delegation pattern to help the compiler catch any programming errors.

Delegation is further investigated this lecture by creating our own protocol and our own delegate.


Homework 4: Delegation
In this lab, you will create a reusable UI component that displays a simple graph of 5 values. The graph will be drawn based upon values that are retrieved from a delegate as defined by a delegate protocol. You will define the delegate and the protocol.

This will be a fairly time consuming lab, and probably the most helpful of any lab for the entire course. Plan to spend some time absorbing the material here.

  • Create an iphone application using the "Single View Application" template.
  • Define a custom protocol named GraphViewProtocol in a GraphViewProtocol.h file.
  • Define a custom class named GraphView derived from UIView that implements a "delegate" property of type id<GraphViewProtocol>.
  • In the InitWithFrame: method of GraphView, add a subview for each bar of the graph.
  • In the drawRect: method, size each bar by asking the delegate for the value.
  • To test the GraphView, modify the array values in a touch event of the UIViewController, then call the setNeedsDisplay method on the GraphView. The setNeedsDisplay method will automatically trigger drawRect: of any view. You never want to call drawRect: directly.
  • Bonus: Add two instances of the GraphView to the screen that display different arrays of values


Lecture 3 - Collection Classes (NSArray, NSDictionary), UITableView, Delegation Introduction - 10/17/2012

In this lecture, we review the Cocoa classes that hold a collection of objects: NSArray, NSDictionary. The UITableView specialized view is demonstrated, and the concept of delegation is introduced.



Homework 3: NSArray, UITableView
  • Create an iphone application using the view-based template.
  • Create a custom class based on NSObject that exposes at least two properties.
  • Create an ivar in the view controller of type NSArray holding at least three instances of your custom class.
  • Add a UITableView to the screen to display the list of objects.


Lecture 2 - More Objective-C, Target/Action - 10/10/2012

In this lecture, we review the startup process of an iOS application from main() to the UIApplicationDelegate's application: didFinishLaunchingWithOptions: method. We continue to investigate Objective-C classes, and started defining a class with the @interface and @implementation keywords. The view hierarchy is reviewed.

The target/action pattern is introduced and an example of this pattern was demonstrated with a UIButton. Here is a link the wikipedia about target/action that might be interesting to check out. Generally speaking, the 'target' of the UIButton will be the UIViewController, and the 'action' will be a method that has been defined in that UIViewController.

Below is a code snippet that was slightly modified after being pulled from this article on stack overflow, which is really your best resource for questions and answers in your iPhone programming efforts:

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(20, 20, 200, 44); // position in the parent view and set the size of the button
[myButton setTitle:@"Click Me!" forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton];


Homework 2: Target/Action
Create an iphone application using the view-based template. Place a UILabel and UIButton onto the screen. Change the content of the UILabel when the UIButton is clicked.

Repeat the assignment twice, once using purely code and once using the graphical Interface Builder.

Lecture 1 - iPhone/iPad Platform and Objective-C - 10/3/2012

In this lecture, the iOS Platform is introduced using the iPad and iPhone. The Objective-C language and its basic elements are introduced.

Objective-C is an programming language that features extensions of the ANSI C language. These extensions are mostly centered around object-oriented programming.

The following Objective-C extensions that are discussed and should be reviewed:
  • @interface
  • @class
  • @property
  • [ ] (square brackets)
  • #import
  • - (minus sign to mark an instance method)
  • + (plus sign to mark an class method)


UCLA_201207_Day1_Demo1.zip project was created during class to demonstrate some of these concepts. See the readme.txt file in the iOS project for more information.
Homework 1: Contact Info, Setting Up Your Development Environment, Basic App
  • Send me an email with iOS in the subject line. This is important so I can whitelist your email address.
  • Read 'Learning Objective-C: A Primer' from Apple. See the link below.
  • Install the current production iOS SDK and XCode.
  • Create an iphone application using the "empty application" template. Display a red UIView object on the screen. See Homework1_201207.zip for a completed solution to the homework assignment.
Apple Documentation - Objective-C, A Primer


XCode Projects - Class Demos, Examples and Homework Answers

Slides

Class Logistics

Previous Versions of iPhone and iPad iOS Development class

home Site Map Terms of Use Privacy Policy Client Directories