iphone 2강

Upload: jaehyeuk-oh

Post on 10-Apr-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 iPhone 2

    1/50

  • 8/8/2019 iPhone 2

    2/50

  • 8/8/2019 iPhone 2

    3/50

    1955 Steve Jobs

    1974 Jobs,

    1975 Jobs, Wozniak, Apple 1

    1985 NeXT Computer

    1986 Avadis Tevanian, NeXTSTEP OS

    1999 NeXTSTEP -> Mac OS X Server1.0,OpenStep Dev Toolkit -> Cocoa

    2008 3.6 iPhone SDK release

  • 8/8/2019 iPhone 2

    4/50

    Application Bundle

  • 8/8/2019 iPhone 2

    5/50

    Application

  • 8/8/2019 iPhone 2

    6/50

    Launch Application

  • 8/8/2019 iPhone 2

    7/50

    Application life cycle

  • 8/8/2019 iPhone 2

    8/50

    Process events

  • 8/8/2019 iPhone 2

    9/50

    Xcode

    Interface Builder

    ,

    GUI

  • 8/8/2019 iPhone 2

    10/50

    Debugging

  • 8/8/2019 iPhone 2

    11/50

    NSLog

  • 8/8/2019 iPhone 2

    12/50

    NSLog String Format Specifiers

    %@ Objective-C, descriptionWithLocale

    %% % character

    %d, %D, %i Signed 32-bit integer (int)%u, %U Unsigned 32-bit integer (unsigned int)

    %x, %X Unsigned 32-bit integer in hexadecimal

    %o, %O Unsigned 32-bit integer in octal

    %f 64-bit floating-point number (double)

    %e, %E 64-bit floating-point number in scientific notation%c 8-bit unsigned character (unsigned char)

    %C 16-bit Unicode character (unichar)

    %s Null-terminated array of 8-bit unsigned characters

    %S Null-terminated array of 16-bit Unicode characters

    %p Void Pointer (void *) in hexadecimal...

  • 8/8/2019 iPhone 2

    13/50

    Class ?

  • 8/8/2019 iPhone 2

    14/50

  • 8/8/2019 iPhone 2

    15/50

    Cocoa Style

    Class Names

    Variable Names

    Method Names

    PreprocessorConstants / Macros

  • 8/8/2019 iPhone 2

    16/50

    Class Names

    capitalized

    NS... (NeXTSTEP)

    prefix ~ namespace

  • 8/8/2019 iPhone 2

    17/50

    Variable Names

    Correct

    Incorrect

    NSString *hostName;

    NSNumber *ipAddress;

    NSArray *accounts;

    NSString *HST_NM;

    NSNumber *theip;

    NSArray *nsma;

    NSString *_name;

  • 8/8/2019 iPhone 2

    18/50

    Method Names

    [fileWrapper writeToFile: path atomically: YES updateFilenames: YES];

    [finder openFile: mailing withApplication: @MailDrop and Deactivate:

    YES];

  • 8/8/2019 iPhone 2

    19/50

    Preprocessor

    constants/Macros

    all capitalized#define MAX_ENTRIES 20

    #ifdef ENABLE_BINDINGS_SUPPORT

  • 8/8/2019 iPhone 2

    20/50

    Mutable objects

    NSArray :

    NSMutableArray :

  • 8/8/2019 iPhone 2

    21/50

    Delegation The Delegating object : a framework

    object The Delegate : a custom controller

    object, typically

    Delegating Object:Delegate = 1:1

  • 8/8/2019 iPhone 2

    22/50

    Notification

    Receiver:Poster = n:1

    Poster can send any message

  • 8/8/2019 iPhone 2

    23/50

    Cocoa Fundamentals Guide

  • 8/8/2019 iPhone 2

    24/50

    Objective-C

  • 8/8/2019 iPhone 2

    25/50

    Objective-C

    ?

    C + Object

  • 8/8/2019 iPhone 2

    26/50

    Object

    ,

  • 8/8/2019 iPhone 2

    27/50

    Class

    Object

  • 8/8/2019 iPhone 2

    28/50

    Instance

    Class

  • 8/8/2019 iPhone 2

    29/50

    Method

    Message Method.

  • 8/8/2019 iPhone 2

    30/50

    Framework

    Class Class Library

    .framework

  • 8/8/2019 iPhone 2

    31/50

    Objective-CCode

  • 8/8/2019 iPhone 2

    32/50

    id (4) : pointer to Object

    nil : a null Object instance

    BOOL (char, 1) : YES 1, NO 0

    char (1), int (4), short (2), long (4), longlong (8), double (8)

    Types

  • 8/8/2019 iPhone 2

    33/50

    Operators

    +, -, /, *, %

    >, >=, ==, !=,

  • 8/8/2019 iPhone 2

    34/50

    Conditions

    ifif (test) do_something

    else if (test) do_something_else

    else ...

  • 8/8/2019 iPhone 2

    35/50

    Loops

    while (test) {statement;}

    do {} while (test);

    for (...;...;...) {}

  • 8/8/2019 iPhone 2

    36/50

    Defining a class

    @interface ... @end

    @implementation

    @interface ClassName : ItsSuperClass{

    instance variable declarations

    }

    method declarations

    @end

    #import ClassName.h

    @implementation ClassName

    method definitions

    @end

  • 8/8/2019 iPhone 2

    37/50

    Method Declaration

    MethodType (ReturnType) MethodName: (argumentType)

    argumentName ...;

    MethodType + : class method

    MethodType - : instance method

  • 8/8/2019 iPhone 2

    38/50

    Object Instantiation

    id anObject = [[SomeClass alloc] init];

    [anObject release];

  • 8/8/2019 iPhone 2

    39/50

    Object Method Call

    [receiver message];

    [aRect setOriginX:30 y:50];

    [aRect setColor:[otherRect color]];

    self, super

  • 8/8/2019 iPhone 2

    40/50

    NSObject, Reference counter

    new, alloc :, ref count +1

    retain : ref count +1

    copy :, ref count+1

    release : ref count -1

    autorelease : ref count -1

  • 8/8/2019 iPhone 2

    41/50

    cont

    dealloc method : instancerelease

    alloc : release = 1:1

  • 8/8/2019 iPhone 2

    42/50

    References

    #import

    #include

  • 8/8/2019 iPhone 2

    43/50

    Property

    @property (attributes [,attribute2, ...]) type name;

    readwrite / readonly

    assign / retain / copy

    / nonatomic

    [self setATable:nil];

    ==[aTable release];

    aTable = nil;

  • 8/8/2019 iPhone 2

    44/50

    Property cont

    @synthesize : setter, getter

    Interface Builder outlet

    @property float value;

    ==

    - (float) value;

    - (void) setValue: (float) newValue;

    @property (nonatomic, retain) IBOutlet NSButton *myButton;

  • 8/8/2019 iPhone 2

    45/50

    Protocol

    @protocol@protocol ProtocolName

    method declarations@end

  • 8/8/2019 iPhone 2

    46/50

    Category

    Add Methods to Class

    #import ClassName.h

    @interface ClassName (CategoryName)

    // method declarations

    @end

    #import ClassName+CategoryName.h

    @implementation ClassName (CategoryName)

    // method definitions@end

  • 8/8/2019 iPhone 2

    47/50

    Interface Builder

    Constants IBOutlet

    IBAction- (IBAction) respondToButtonClick : (id)sender;

    @interface MyClass : NSObject {

    NSView * aViewOutlet;

    }@property (nonatomic, retain) IBOutlet NSView * aViewOutlet;

    ...

    @synthesize aViewOutlet;

  • 8/8/2019 iPhone 2

    48/50

    Fast Enumeration

    NSArray, NSDictionary, NSSet,NSEnumerator, ...

    NSArray *array = [NSArray arrayWithObjects:@1, @2, @3, nil];

    for (NSString *string in array) {

    NSLog(@string is %@, string);

    }

  • 8/8/2019 iPhone 2

    49/50

    Selector

    Class Method tableindex

    @selector

    [myButtonCell

    setAction:@selector(DoSomething:)];

  • 8/8/2019 iPhone 2

    50/50

    Developer Document

    NSObject

    NSArray

    NSMutableArray

    NSString