Lecture Presentation

Lecture Presentation


  • iOS Development
  • iOS SDK and Xcode
  • Single View Application

Platforms and technologies

  • Supported operating systems for development
    • Android: Supported on Windows, Mac OS X and Linux
    • iOS: Supported only on Mac OS X
  • Development environment
    • Android: Eclipse is free and open source (other alternatives exist)
    • iOS: Xcode is free in the Mac App Store
  • Language
    • Android: Java, strongly typed, descendant of the C language
    • iOS: Objective-C, more loosely typed, compatible with the C language


  • Stores
    • Android: Google Play Store, Amazon App Store and more
    • iOS: iTunes App Store
  • Submitting your own apps to the store
    • Android: Apps are available as soon as you upload it (some malicious code screening)
    • iOS: Apps are checked by Apple employees and must conform to standards, 1-2 weeks
  • Getting apps onto devices without the store
    • Android: Any app can be downloaded and installed over internet (Untrusted sources must be turned on)
    • iOS: An app can be downloaded and installed if device id is known and registered when building app, limit of 100 devices

Developer Support

  • Registration
    • Android: Google Play Store $25 one time fee
    • iOS: iOS Developer Program Membership $99 per year
  • Income
    • Both stores give 70% to the developer when selling apps


  • Xcode and the iOS SDK is contained in the same package when installing from Mac App Store
  • Core Foundation
    • C language
    • Low level memory structures
  • Cocoa Touch, UIKit
    • Objective-C language
    • User interface widgets/views

Almost identical between Objective-C and Java

  • Both originates from the C language
  • Blocks of code inside curly braces { and }
  • Statements finished with semicolon ;
  • Variables, declarations, assignments etc
  • Selective statements like if, if-else, comparisions etc
  • Iterative statements like for and while

Differences between Objective-C and Java

  • How classes/code are put in files
    • Java forces one class for each file. One single file for each class.
    • Objective-C follows C in separating the class declaration and implementation into two different files. Convention to have one pair of file for each class but not enforced by the language.
  • Strictness in objects and methods
    • Java is very strict. In order to call a method it must be known by compiler from the class definition.
    • Objective-C is more loosely typed. Can write code where a method is called, without knowing for sure if it will be there when the code runs. Methods can be added dynamically while the application is running.

Objective-C syntax characters

  • Special keywords start with @
    • @interface
  • Class members
    • Instance method members start with -
    • Class (static) method members start with +
  • Statements in Objective-C are put inside [ and ]
    • This is the main features that makes Objective-C code backwards compatible with C. Everything inside of [ and ] are Objective-C statements and most other statements are valid C code.

Objective-C objects and method calls

  • Object variables/references are pointers, declared with *
  • Create a new object of a class
    MyClass* obj = [[MyClass alloc] init];
  • Call a method on an object
    // Corresponding to obj.doSomething() in Java
    [obj doSomething];
    // Corresponding to obj.calcSomething(123, 456) in Java
    [obj calcSomething:123 withSecondArgument:456];
  • In Objective-C, the term is "sending a message to an object"

String concatenation

  • Objective-C
    NSString* firstname = @"Adam";
    NSString* lastname = @"Ant";
    NSString* name = [[firstname stringByAppendingString:@" "] stringByAppendingString:lastname];
    int age = 25;
    NSString* text = [NSString stringWithFormat:@"My name is %@ %@ and I'm %d years old",
      firstname, lastname, age];
  • Java
    String firstname = "Adam";
    String lastname = "Ant";
    String name = firstname + " " + lastname;
    int age = 25;
    String text = String.format("My name is %s %s and I'm %d years old",
      firstname, lastname, age);

String and integer conversion

  • Objective-C
    int number = 123;
    NSString* str = [NSString stringWithFormat:@"%d", number];
    NSString* numstr = @"123";
    int num = [numstr intValue];
  • Java
    int number = 123;
    String str = Integer.toString(number);
    String numstr = "123";
    int num = Integer.parseInt(numstr);

Class with members

  • Objective-C
    @interface MyClass : NSObject {
      int _value;
    @implementation MyClass
    -(void)increase {
  • Java
    public class MyClass extends Object {
      public int _value;
      public void increase() {

Building a user interface

  • Built graphically (not using xml)
    • Even though what is saved is actually an xml file, you never edit it directly
  • Interface Builder
    • Name of the previous application for building the user interface. Nowadays integrated into the Xcode application.
  • Storyboard
    • A more recent addition where you can design not just single screens, but the flow between multiple screens, mapping buttons to new screens etc.

Connecting to visual elements

  • A reference in Objective-C to a visual object on screen is called an Outlet
  • Outlets are declared as instance variables (or properties) in the view controller
  • Create
    • Show split window in Interface Builder with ViewController.h to the right
    • Right-click visual object in Interface Builder
    • Drag "Creating new referencing outlet" to the instance member section { } of the view controller source code


  • Events can be handled
    • By implementing a protocol (similar to implementing an interface in Java)
    • By binding the event to a specific method in the view controller
    • Usually it depends on the event what procedure must be used
  • Bind an event to a method in Objective-C
    • Show split window in Interface Builder with ViewController.h to the right
    • Right-click visual object in Interface Builder
    • Find event and drag it to the class declaration (outside/after any { })

Some common events

  • UIButton, Touch Up Inside
    • This is similar to onClick on Android
  • Slider, Value Changed
    • Fires each time the user drags the thumb of a Slider control on screen