iOs app 101

download iOs app 101

of 91

  • date post

    11-Sep-2014
  • Category

    Design

  • view

    960
  • download

    0

Embed Size (px)

description

 

Transcript of iOs app 101

  • iOS App 101And how fun is it ?

    by tomjpsun

    1275

  • About me

    MFC Certificate WDM driver (USB)

    1275

  • About me

    MFC Certificate WDM driver (USB)

    Linux driver iOS App

    1275

  • About me

    MFC Certificate WDM driver (USB)

    Linux driver iOS App

    1275

  • About me

    MFC Certificate WDM driver (USB)

    Linux driver iOS App

    1275

  • About me

    MFC Certificate WDM driver (USB)

    Linux driver iOS App

    Not interest any more

    1275

  • Agenda

    Development Environment Objective-C Cocoa Design patterns UX References

    1275

  • Agenda

    Development Environment Objective-C Cocoa Design patterns UX References

    1275

  • XCode

    iOS ver XCode ver

    OS X ver

    5.1 4.3 10.7(Lion)

    5.0 below 4.2 10.6.8(Leopard)

    Strictly depends on

    Tested combinations

    1275

  • https://developer.apple.com/programs/

    1275

  • iOS Dev Centerhttps://developer.apple.com/devcenter/ios/index.action

    1275

  • Provision profile

    Your Mac Dev Center

    1275

  • Demo Create an empty App Browse XCode features organizer project configurations simulator download debug

    1275

  • Agenda

    Development Environment Objective-C Cocoa Design patterns UX References

    1275

  • Object oriented

    1275

  • Message passing

    [instance method];

    iOS

    1275

  • Dynamismobjective-C runtime library

    1275

  • .h#import

    @interface Fraction: NSObject{ int numerator; int denominator;}-(void) print;-(void) setNumerator: (int) n;-(void) setDenominator: (int) d;@end

    1275

  • .m#import "Fraction.h"

    @implementation Fraction-(void) print{ NSLog(@"%i/%i", numerator, denominator);}-(void) setNumerator: (int) n{ numerator = n;}-(void) setDenominator: (int) d{ denominator = d;}@end

    1275

  • Multiple arguments-(void) setTo: (int) n over: (int) d

    { numerator = n; denominator = d;}

    int main (int argc, char *argv[]){ Fraction *aFraction = [[Fraction alloc] init]; [aFraction setTo: 1 over: 3]; [aFraction print]; // -> 1/3 return 0;}

    1275

  • Class method@interface Fraction: NSObject{ int numerator; int denominator;}

    @interface FractionFactory: NSObject

    +(Fraction*) newFractionWithNumerator: (int)numerator andDenominator: (int)denominator;

    int main (int argc, char *argv[]){ Fraction* f = [FractionFactory newFractionWithNumerator: 1 andDenominator: 2];}

    1275

  • Synthesized accessor#import

    @interface Fraction: NSObject{ int numerator;}-(void) setNumerator: (int) n; // setter-(int) numerator; // getter@end

    @interface Fraction: NSObject@property numerator;@end

    @implementation Fraction@synthesis numerator;@end

    compiler generates getter/setter

    1275

  • Dot accessing property[ instance setPoperty: 2];

    is equal to

    instance.property = 2;

    1275

  • self

    self like this in C++- (id)init{ self = [super init]; if (self) { // Custom initialization } return self;}

    1275

  • id

    something like void* useful at runtime

    1275

  • selector

    name of method , function literal compile time

    SEL aSelector = @selector(methodName);

    run timeSEL aSelector = NSSelectorFromString(@"print"); NSString* selectorStr =

    NSStringFromSelector(aSelector);

    NSLog(@"%@", selectorStr);

    1275

  • selector[friend performSelector:@selector(gossipAbout:)

    withObject:aNeighbor];

    is equal to

    [friend gossipAbout:aNeighbor];

    1275

  • Runtime library

    compile time, link time run time

    1275

  • object A-(void)fly

    object B-(void)fly

    SEL userSelector = NSSelectorFromString(@fly);[ any performSelector: @selector(userSelector) ];

    any object A, A flyany object B, B fly

    1275

  • Category extending class (even if you dont have the

    source)

    #import "High.h"

    @interface High (calculate)- (NSInteger) plus:(NSInteger)operand1 and:(NSInteger)operand2;@end

    @implementation High (calculate)- (NSInteger) plus:(NSInteger)operand1 and:(NSInteger)operand2{ return operand1 + operand2;}@end

    1275

  • Class extension

    category without name used as private method declaration in Obj-

    C

    1275

  • Category may cause chaos

    category wins over the override function define same function in different

    categories. Lead to undefined condition.

    1275

  • @protocol

    class with only methods. classes functions.

    @protocol MyXMLSupport

    - initFromXMLRepresentation:(NSXMLElement *)XMLElement;

    - (NSXMLElement *)XMLRepresentation;

    @end

    1275

  • memory management

    MRC - manual reference counting ARC - automatic reference counting garbage collection - in OS X, not in iOS

    1275

  • MRC

    Apples rule - owner release (owner: copy, alloc, retain)

    burden on developers// retain release pairid value = [dict retain];[value release];

    // autoreleasearray = [[NSMutableArray new] autorelease];

    1275

  • ARC

    supported on LLVM 3.0 generate release code for you.

    1275

  • Blocksthis section is borrowed from WWDC 2011, sec. block

    and central dispatch

    * ^1275

  • Functions Blocks

    // body of code{

    return a - b;

    }

    // pointer to a function*

    // body of code{

    return a - b;

    }

    // pointer to a block^

    1275

  • Functions Blocks

    // body of code{

    return a - b;

    }

    // pointer to a functionint (*cmpr)(int, int);

    // body of code{

    return a - b;

    }

    // pointer to a blockint (^cmpr)(int, int);

    1275

  • Functions Blocks

    // body of code{

    return a - b;

    }

    // pointer to a functionint (*cmpr)(int, int);

    typedef int (*func_t) (int, int);

    // body of code{

    return a - b;

    }

    // pointer to a blockint (^cmpr)(int, int);

    typedef int (^block_t)(int, int);

    1275

  • Functions Blocks

    // body of code{

    return a - b;

    }

    // pointer to a functionint (*cmpr)(int, int);

    typedef int (*func_t) (int, int);

    func_t cmpr = arg;

    // body of code{

    return a - b;

    }

    // pointer to a blockint (^cmpr)(int, int);

    typedef int (^block_t)(int, int);

    block_t cmpr = arg;

    1275

  • Functions Blocks

    // body of code{

    return a - b;

    }

    // pointer to a functionint (*cmpr)(int, int);

    typedef int (*func_t) (int, int);

    func_t cmpr = arg;

    cmpr(x, y);

    // body of code{

    return a - b;

    }

    // pointer to a blockint (^cmpr)(int, int);

    typedef int (^block_t)(int, int);

    block_t cmpr = arg;

    cmpr(x, y);

    1275

  • Functions Blocks

    // body of code{

    return a - b;

    }

    // pointer to a function*

    // body of code{

    return a - b;

    }

    // pointer to a block^

    1275

  • Functions Blocks

    // body of codeint my_cmp(int a, int b){

    return a - b;

    }

    // body of code^(int a, int b){

    return a - b;

    }

    1275

  • Functions Blocks

    // body of code

    int my_cmp(int a, int b){

    return a - b;

    }

    // usage

    sort(array, 10, my_cmp);

    // body of code

    ^(int a, int b){

    return a - b;

    }

    // usage

    sort(array, 10, ^(int a, int b){ return a - b;});

    1275

  • Blocks

    // body of code

    ^(int a, int b){

    return a - b;

    }

    closure

    1275

  • Blocks

    // body of code__block int cnt = 0;^(int a, int b){ cnt++ ; return a - b;

    }

    log(Count: %d, cnt);

    closure

    1275

  • Agenda

    Development Environment Objective-C Cocoa Design patterns UX References

    1275

  • Cocoa fit in iOS

    App UIKit

    1275

  • UIKit Philosophy

    MVC

    1275

  • View Controllers

    1275

  • Anatomy

    1275

  • View Controllers Manage Views

    1275

  • View Controllers Manage Views

    1275

  • View Controllers Manage Views

    1275

  • View

    1275

  • Important Documents

    View Controller Programming Guide for iOSView Programming Guide

    1275

  • Agenda

    Development Environment Objective-C Cocoa Design patterns UX References

    1275

  • delegate

    iOSUIApplication

    object

    MyAppdelegate

    implemented via @protocol

    1275

  • delegate

    iOSUIApplication

    object

    MyAppApp

    delegateimplemented via @protocol

    1275

  • delegate

    iOSUIApplication

    object

    MyAppApp

    delegateimplemented via @protocol

    1275

  • delegate

    iOSUIApplication

    object

    MyAppApp

    delegateimplemented via @protocol

    1275

  • delegate

    iOSUIApplication

    object

    MyAppdelegate

    implemented via @protocol

    1275

  • delegate

    iOSUIApplication

    object

    MyAppApp

    delegateimplemented via @protocol

    1275

  • delega