Slide 1

Slide 1 text

My Way to Obj-C

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

programming

Slide 4

Slide 4 text

exp ≈ 15 years

Slide 5

Slide 5 text

but not solid at all ..orz

Slide 6

Slide 6 text

Flash/ActionScript

Slide 7

Slide 7 text

exp ≈ 7 years

Slide 8

Slide 8 text

Ruby

Slide 9

Slide 9 text

exp ≈ 3.5 years

Slide 10

Slide 10 text

Obj-C

Slide 11

Slide 11 text

exp ≈ 2 years

Slide 12

Slide 12 text

real exp ≈ 0.5 years

Slide 13

Slide 13 text

I learn a lot from those languages.

Slide 14

Slide 14 text

Obj-C

Slide 15

Slide 15 text

Obj-C is a dynamic language.

Slide 16

Slide 16 text

OO from smalltalk

Slide 17

Slide 17 text

send message

Slide 18

Slide 18 text

# Ruby class Animal def say_something(words) puts words end end cat = Animal.new cat.say_something "hello, world"

Slide 19

Slide 19 text

// Obj-C [cat saySomething: @"Hello, World"];

Slide 20

Slide 20 text

# Ruby cat.send :say_something, "Hello, World"

Slide 21

Slide 21 text

but what if the cat doesn't know how to talk?

Slide 22

Slide 22 text

nil is fine with all messages which it doesn't know :)

Slide 23

Slide 23 text

protocol

Slide 24

Slide 24 text

@protocol Talking - (void)saySomething:(NSString *)word; @end

Slide 25

Slide 25 text

// Animal.h @interface Animal @end

Slide 26

Slide 26 text

// Animal.m @implement Animal - (void)saySomething:(NSString *)word { // say something here.. :) } @end

Slide 27

Slide 27 text

category

Slide 28

Slide 28 text

monkey patching

Slide 29

Slide 29 text

# Ruby class String def say_hi puts "hi, there" end end "eddie".say_hi # hi, there

Slide 30

Slide 30 text

// NSString+MyHelloString.h #import @interface NSString (MyHelloString) - (void) say_hi; @end

Slide 31

Slide 31 text

// NSString+MyHelloString.m #import "NSString+MyHelloString.h" @implementation NSString (MyHelloString) -(void) say_hi{ NSLog(@"hi, there"); } @end

Slide 32

Slide 32 text

// Cat.h #import "NSString+MyHelloString.h"

Slide 33

Slide 33 text

// Cat.m [@"eddie" say_hi];

Slide 34

Slide 34 text

id

Slide 35

Slide 35 text

dynamic typing

Slide 36

Slide 36 text

// Cat.h @interface Cat - (IBAction)clickButton:(id)sender; @end

Slide 37

Slide 37 text

- (id)init { self = [super init]; if (self) { // do some init things here } return self; }

Slide 38

Slide 38 text

block

Slide 39

Slide 39 text

^

Slide 40

Slide 40 text

# Ruby 10.times { |i| puts i }

Slide 41

Slide 41 text

# obj-c [kids enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { // do something }];

Slide 42

Slide 42 text

GCD

Slide 43

Slide 43 text

# obj-c dispatch_queue_t queue = dispatch_queue_create("imageLoadingQueue", NULL); dispatch_async(queue, ^{ // start to load image here dispatch_async(dispatch_get_main_queue(), ^{ // image loaded, do something here }); });

Slide 44

Slide 44 text

coding exp from Flash/ ActionScript and Ruby

Slide 45

Slide 45 text

Obj-C and Ruby have the same parent

Slide 46

Slide 46 text

smalltalk

Slide 47

Slide 47 text

I learn dynamic programming from Ruby

Slide 48

Slide 48 text

I learn block from Ruby

Slide 49

Slide 49 text

Obj-C is not difficult to learn.

Slide 50

Slide 50 text

Cocoa Framework is.

Slide 51

Slide 51 text

I learn UI inheritance from Flash/ActionScript

Slide 52

Slide 52 text

https://developer.apple.com/Library/ios/#docum Cocoa/Conceptual/CocoaFundamental CocoaDesignPatterns/CocoaDesignPattern

Slide 53

Slide 53 text

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/WhatIsCocoa/WhatIsCocoa.html

Slide 54

Slide 54 text

Essential ActionScript 3.0 p.459

Slide 55

Slide 55 text

event handling

Slide 56

Slide 56 text

async handling

Slide 57

Slide 57 text

cocos2d

Slide 58

Slide 58 text

But..

Slide 59

Slide 59 text

delegation

Slide 60

Slide 60 text

Obj-C is subset of C

Slide 61

Slide 61 text

memory management

Slide 62

Slide 62 text

retain v.s release

Slide 63

Slide 63 text

-(NSString *) getBookName { NSString *the_name = @"This is a book"; return the_name; }

Slide 64

Slide 64 text

-(NSString *) getBookName { NSString *the_name = @"This is a book"; [the_name release]; return the_name; }

Slide 65

Slide 65 text

autorelease http://blog.eddie.com.tw/2010/11/25/autorelease-in-objective-c/

Slide 66

Slide 66 text

-(NSString *) getBookName { NSString *the_name = @"This is a book"; return [the_name autorelease]; }

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

ARC Automatic Reference Counting

Slide 69

Slide 69 text

ARC knows more Obj-C than you :)

Slide 70

Slide 70 text

new style Obj-C syntax

Slide 71

Slide 71 text

literal syntax sugar

Slide 72

Slide 72 text

NSNumber* age = [NSNumber numberWithInt:18];

Slide 73

Slide 73 text

NSNumber* age = @18;

Slide 74

Slide 74 text

NSNumber* pi = [NSNumber numberWithFloat:3.1415926F];

Slide 75

Slide 75 text

NSNumber* pi = @3.1415926F;

Slide 76

Slide 76 text

NSArray* kids = [NSArray arrayWithObjects:@"高思", @"高齊", nil];

Slide 77

Slide 77 text

NSArray* kids = @[@"高思", @"高齊"];

Slide 78

Slide 78 text

NSDictionary* kidsEnglishName = [NSDictionary dictionaryWithObjectsAndKeys: @"Kose", @"高思", @"Coach", @"高齊", nil];

Slide 79

Slide 79 text

NSDictionary* kidsEnglishName = @{@"高思":@"Kose", @"高齊":@"Coach"};

Slide 80

Slide 80 text

// for-loop style NSArray* kids = ... for (int i = 0; i < kids.count; ++i) { NSString* kid = [kids objectAtIndex:i]; // do something }

Slide 81

Slide 81 text

// for-in style NSArray* kids = ... for (NSString* kid in kids) { // do something }

Slide 82

Slide 82 text

// block style NSArray* kids = ... [kids enumerateObjectsUsingBlock:^(NSString* kid, NSUInteger idx, BOOL *stop) { // do something here }];

Slide 83

Slide 83 text

NSDictionary * kidsEnglishName = ... NSArray* keys = [dict allKeys]; for (NSString* key in keys) { NSString* value = [dict objectForKey:key]; // do something else }

Slide 84

Slide 84 text

// block style NSDictionary * kidsEnglishName = ... [kids enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { // do something here }];

Slide 85

Slide 85 text

Subscripting Methods

Slide 86

Slide 86 text

NSArray* kids = @[@"高思", @"高齊"]; NSLog(@"%@", [kids objectAtIndex:0]); // 高思

Slide 87

Slide 87 text

NSArray* kids = @[@"高思", @"高齊"]; NSLog(@"%@", kids[0]); // 高思

Slide 88

Slide 88 text

NSMutableArray* kids = [@[@"高思", @"高齊"] mutableCopy]; kids[0] = @"狸貓"; NSLog(@"%@", [kids objectAtIndex:0]); // 狸貓

Slide 89

Slide 89 text

NSMutableDictionary* kidsEnglishName = [@{@"高思":@"Kose", @"高齊":@"Coach"} mutableCopy]; kidsEnglishName[@"高思"] = @"Gauss";

Slide 90

Slide 90 text

@synthesize

Slide 91

Slide 91 text

// hello.h @property (nonatomic, strong) NSString* name; // hello.m @synthesize name = _name;

Slide 92

Slide 92 text

// hello.h @property (nonatomic, strong) NSString* name; // hello.m @synthesize name = _name;

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

Conclusion

Slide 95

Slide 95 text

there's no BEST or WORST language

Slide 96

Slide 96 text

non of them are useless

Slide 97

Slide 97 text

code more, complain less

Slide 98

Slide 98 text

完 thank you all :)

Slide 99

Slide 99 text

高見見龍龍 Conacts photo by Eddie Websie Blog Plurk Facebook Google Plus Twiter Email Mobile http://www.eddie.com.tw http://blog.eddie.com.tw http://www.plurk.com/aquarianboy http://www.facebook.com/eddiekao http://www.eddie.com.tw/+ https://twiter.com/#!/eddiekao [email protected] +886-928-617-687