writing ios apps

Upload: kepler1729

Post on 03-Apr-2018

248 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 Writing iOS Apps

    1/30

    Introductions

    I know this is a little lame but...

    Who am I?

    Who are you guys?

    What kind of programming experience do you

    have?

    Any experience with Iphone / mobile

    development?

    What are you hoping to get out of the course?

  • 7/28/2019 Writing iOS Apps

    2/30

    Iphone iOS Architecture

    The iPhone runs the iOS operating system

    IOS is the intermediate layer between your

    applications and the iPhone hardware Made up of various layers working from higher-

    level to lower-level frameworks.

    Prefer higher-level to lower-level

    Cocoa Touch Media Layer

    CoreServices Core OS

  • 7/28/2019 Writing iOS Apps

    3/30

    Iphone SDK

    You would get the SDK from developer.apple.com

    What you get:

    SDK All the libraries and frameworks needed todevelop Iphone applications

    Xcode Tools

    Xcode IDE for application development

    Interface Builder visual tool for building Uis

    Instruments runtime performance and debugging

    Iphone/Ipad simulator

    iOS Reference Library - documentation

  • 7/28/2019 Writing iOS Apps

    4/30

    iOS Architecture Layers

    Cocoa Touch Layer

    Handle interaction with other layers, including UI

    Features: Multitasking (4.0)

    Wireless Printing (4.2)

    Push and Local (4.0) Notifications

    View Controllers

    and more

    Frameworks:

    UIKit, GameKit, Map Kit, Event Kit, and more...

  • 7/28/2019 Writing iOS Apps

    5/30

    IOS Architecture Layers

    Media Layer

    Used for graphics, audio, and video

    Graphics can handle 2D, 3D, and many image formats Audio frameworks and formats

    Media player framework, AV Foundation framework, OpenAL, Core

    Audio framework

    Format: AAC, ALAC, A-law, IMA4, Linear PCM, u-law, Intel IMA

    ADPCM, Microsoft GSM 6.1, AES3-2003

    Video frameworks and formats

    Media player, AV foundation, and core media

    H.264 (.m4v, .mp4, .mov), MPEG-4 (.m4v, .mp4, .mov)

    Can also play audio formats

  • 7/28/2019 Writing iOS Apps

    6/30

    iOS Architecture Layers (cont.)

    Core Services Layer

    Provides system services generally used by

    higher-level layers Features: InApp Purchase, Location Service,

    SQLite, XML Support, GCD (4.0)

    Core OS Layer

    Lowest-level features, close to hardware

    Features: External Access, Accessories,

    Security, Kernel/low-level unix

  • 7/28/2019 Writing iOS Apps

    7/30

    Xcode Creating a project

    Navigation based application

    presents data heirarchicaly across multiple

    screens. Example Contacts App OpenGL ES application

    application that uses openGL to present images

    or animation Split-View based application

    unique to Ipad, multiple views on screen,

    presented using master-detail or source-list

  • 7/28/2019 Writing iOS Apps

    8/30

    Xcode Creating a project (cont.)

    Tab-Bar Application

    application with a radio button bar to navigate

    Utility Application

    App with main view, and flip-side view

    View-based Application

    application uses a single view

    Window-based Application

    provides an empty window to design your own

    view hierarchy

  • 7/28/2019 Writing iOS Apps

    9/30

    Basic App Structure

    What are all these files?

    Frameworks

    These provide the interfaces we need to write

    applications

    CoreGraphics: Media Layer 2D vector graphics

    Foundation: Core Services Layer, containsmany basic functions such as Collections,

    Strings, Threads, and URL management

    UiKit: Cocoa Touch Layer, UI interfaces

  • 7/28/2019 Writing iOS Apps

    10/30

    Basic App Structure

    .plist files

    contains project information

    sets initial view and bundle information

    .pch

    prefix header that generally applies to all files in

    the project .xib

    bundle that contains all the information on the

    view built in interface builder

  • 7/28/2019 Writing iOS Apps

    11/30

    Basic App Structure

    .h files

    Header files common to many languages

    used for variable and property declaration .m files

    source code files

    contain all the functional code views can also be created and configured in these

    files.

  • 7/28/2019 Writing iOS Apps

    12/30

    Creating our first app

    Create a new View-based Application

    Open interface builder double click

    MainWindow.xib Add a label

    Add text to label

    Format text

    Run application

  • 7/28/2019 Writing iOS Apps

    13/30

    Interface Builder

    Library Window

    Objects, instances of the main interface classes we

    can drag and drop into our application We'll look at a few individually

    Classes, list of classes Interface builder finds

    available

    build your custom class in xcode instantiate through IB

    Media, access media from the resources folder in

    the IB context

  • 7/28/2019 Writing iOS Apps

    14/30

    Interface Builder

    Inspector Window

    Attributes: Object specific configuration

    Effects: Any Core-Animation, Core-Graphics Size: Control size and position

    Bindings: Display bindings, can use to connect

    Connections: display the outlets and actions Identity: Information to help identify the object

  • 7/28/2019 Writing iOS Apps

    15/30

    Interface Builder

    Connections Panel

    accessed via control-click, quick way to set up

    connections

    Outlets: the outlets exposed by the object Sent Actions: shows target of action message

    Received Actions: Incoming actions handled

    Accessibility: for storing, all visual objects have Accessibility References: list of objects that refer to

    this through accessibility connection

    Referencing Outlets: objects that reference through

    an outlet

  • 7/28/2019 Writing iOS Apps

    16/30

    Interface Builder

    Outlets

    IBOutlet UIButton *myButton

    creates a signal for interface builder Interestingly here is the definition in code:

    #ifndef IBOutlet

    #define IBOutlet

    #endif

    Interface builder scans for these then uses the to

    allow you to make connections.

  • 7/28/2019 Writing iOS Apps

    17/30

    Interface Builder

    Actions

    Method in your controller class

    Declared with the IBAction keyword - (IBAction)myMethod:(id)sender

    return type of IBAction = void

    usually has an argument of the id of the calling

    object, or has no arguments

    old code may have the id argument but not use it,

    older versions of cocoa touch required this

  • 7/28/2019 Writing iOS Apps

    18/30

    Objective C

    Objects and Classes

    Classes require both .h and .m file

    Interface declaration, variables and methods

  • 7/28/2019 Writing iOS Apps

    19/30

    Interfaces/Classes

    Parent Class single inheritance

    Variables

    Strongly Typed: *; Weakly Typed (dynamic): id ;

    * = pointer, type id implies a pointer

    Dynamic Typing in Objective C Like Object type from java (typed at runtime)

    isa instance variable provides info on class

  • 7/28/2019 Writing iOS Apps

    20/30

    More on variables and properties

    Special Values

    nil like null, we'll discuss more about this soon

    self works like in Java and most otherlanguages, can access get/set messages or

    methods

    @private, @protected, @public, directives

    used to specify scope and access

    a couple other important directives @interface,

    and @implementation

  • 7/28/2019 Writing iOS Apps

    21/30

    Properties

    Objective C has some preprocessor directives for

    creating accessor functions

    @property begins the declaration of a property after interface, can set attributes

    getter, setter: allows you to set the getter or setter

    name

    retain: applies the retain method to the property to

    avoid getting garbage collected

    atomic/nonatmoic: robust access during

    multithreading

  • 7/28/2019 Writing iOS Apps

    22/30

    Properties cont.

    Used to create interface builder outlets

    @synthesize requests the compiler generate accessors

    for the listed properties.

    inside implementation

    Examples:

    @property (retain, nonatmoic) IBOutlet NSString *myString;

    @property (retain, setter=setName) NSString *myName;

    @property (readonly) int numStudents;

  • 7/28/2019 Writing iOS Apps

    23/30

    Interfaces - Methods

    Two types instance ( - ) and class ( + )(static)

    Method name insertObject:atIndex:

    Parameters (type) Name

    Methods have access to class variables

  • 7/28/2019 Writing iOS Apps

    24/30

    Calling an object - Messaging

    Syntax [receiver selector: arguments]

    Also can be thought of as [receiver message]

    Message signature plus parameter information [myArray insertObject: atIndex:0]

    [myRectangle display] call rectangles display option

    [myRectangle setWidth:20.0] setting a parameter messages can be sent to nil and will always return nil

    [myRectangle setWidth:[yourRectangle width]]

  • 7/28/2019 Writing iOS Apps

    25/30

    Messages Cont.

    Nesting messages

    [[myAppObject theArray] inserObject:

    [myAppObject objectToInsert] atIndex:0]

    dot syntax available for accessor methods

    myAppObject.theArray = aNewArray;

    [myAppObject setTheArray:aNewArray];

    copyArray = myAppObject.theArray;

    copyArray = [myAppObject theArray];

  • 7/28/2019 Writing iOS Apps

    26/30

    Classes and Data Types

    Mutable vs. Immutable

    Mutable

    NSMutable- Array, Set, Dictionary, IndexSet,CharacterSet, Data, String, UrlRequest

    Immutable

    remove the Mutable Why is this important/useful?

  • 7/28/2019 Writing iOS Apps

    27/30

    Classes and Data Types

    NSString/NSMutableString

    NSString preprocessor directive @my string

    length characterAtIndex:

    getCharacters:range:

    initWithFormat: compare:options:range:

  • 7/28/2019 Writing iOS Apps

    28/30

    Classes and Data Types

    NSArray/NSMutableArray

    insertObject:atIndex:

    removeObjectAtIndex: addObject:

    removeLastObject

    replaceObjectAtIndex:withObject: initWithObjects:

  • 7/28/2019 Writing iOS Apps

    29/30

    Other Classes and Data Types

    NSDictionary Key:Value pair

    NSSet unordered collection of distinct

    elements int, double, BOOL etc.

  • 7/28/2019 Writing iOS Apps

    30/30

    Creating An App

    Add a Button

    Add a NSString

    We'll use this to set the label text Add a method for the button

    The method should change the label text

    Connect UI to the Code Success?? We hope.