Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
My Way to Objective-C
高見龍
November 22, 2012
Programming
6
600
My Way to Objective-C
高見龍
November 22, 2012
Tweet
Share
More Decks by 高見龍
See All by 高見龍
閱讀原始碼 - 再戰十年的 jQuery
eddie
1
460
Learn JavaScript Well
eddie
1
1.1k
How to Learn Web Framework Correctly
eddie
4
1.8k
about-5xruby
eddie
0
90
Ruby on Rails 2018 年進化論
eddie
0
120
10 years in learning Ruby
eddie
5
1.3k
傳說中可以治百病的區塊鏈是怎麼一回事?
eddie
0
1.7k
Git Branch
eddie
0
320
Refactoring (Ruby edition)
eddie
0
220
Other Decks in Programming
See All in Programming
Qiita Night PHP 2023
fuwasegu
0
11k
Circuit⚡
monaapk
0
200
Remix + Cloudflare Pages + D1 で ポケモン SV のレンタルチームを検索できるアプリを作ってみた
kuroppe1819
4
1.3k
SwiftPMのPlugin入門 / introduction_to_swiftpm_plugin
uhooi
2
100
OIDC仕様に準拠した Makuake ID連携基盤構築の裏側
ymtdzzz
0
550
子育てとEMと転職と
_atsushisakai
1
410
Gradle build: The time is now
nonews
1
470
Findy - エンジニア向け会社紹介 / Findy Letter for Engineers
findyinc
2
42k
Cloudflare Workersと状態管理
chimame
3
480
社会人 20 年目エンジニア、発信で技術学びなおしてる話
e99h2121
1
140
はてなリモートインターンシップ2022 フロントエンドブートキャンプ 講義資料
hatena
0
120
まだ日本国内で利用できないAppActionsにトライしてみた / MoT TechTalk #15
mot_techtalk
0
110
Featured
See All Featured
The Power of CSS Pseudo Elements
geoffreycrofte
52
4.3k
Creatively Recalculating Your Daily Design Routine
revolveconf
207
11k
Code Reviewing Like a Champion
maltzj
508
38k
Optimizing for Happiness
mojombo
365
64k
Streamline your AJAX requests with AmplifyJS and jQuery
dougneiner
128
8.8k
GraphQLの誤解/rethinking-graphql
sonatard
39
7.8k
For a Future-Friendly Web
brad_frost
166
7.8k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
6
840
Fashionably flexible responsive web design (full day workshop)
malarkey
396
63k
Clear Off the Table
cherdarchuk
79
290k
Build your cross-platform service in a week with App Engine
jlugia
221
17k
GraphQLとの向き合い方2022年版
quramy
20
9.9k
Transcript
My Way to Obj-C
None
programming
exp ≈ 15 years
but not solid at all ..orz
Flash/ActionScript
exp ≈ 7 years
Ruby
exp ≈ 3.5 years
Obj-C
exp ≈ 2 years
real exp ≈ 0.5 years
I learn a lot from those languages.
Obj-C
Obj-C is a dynamic language.
OO from smalltalk
send message
# Ruby class Animal def say_something(words) puts words end end
cat = Animal.new cat.say_something "hello, world"
// Obj-C [cat saySomething: @"Hello, World"];
# Ruby cat.send :say_something, "Hello, World"
but what if the cat doesn't know how to talk?
nil is fine with all messages which it doesn't know
:)
protocol
@protocol Talking - (void)saySomething:(NSString *)word; @end
// Animal.h @interface Animal<Talking> @end
// Animal.m @implement Animal - (void)saySomething:(NSString *)word { // say
something here.. :) } @end
category
monkey patching
# Ruby class String def say_hi puts "hi, there" end
end "eddie".say_hi # hi, there
// NSString+MyHelloString.h #import <Foundation/Foundation.h> @interface NSString (MyHelloString) - (void) say_hi;
@end
// NSString+MyHelloString.m #import "NSString+MyHelloString.h" @implementation NSString (MyHelloString) -(void) say_hi{ NSLog(@"hi,
there"); } @end
// Cat.h #import "NSString+MyHelloString.h"
// Cat.m [@"eddie" say_hi];
id
dynamic typing
// Cat.h @interface Cat - (IBAction)clickButton:(id)sender; @end
- (id)init { self = [super init]; if (self) {
// do some init things here } return self; }
block
^
# Ruby 10.times { |i| puts i }
# obj-c [kids enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
// do something }];
GCD
# 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 }); });
coding exp from Flash/ ActionScript and Ruby
Obj-C and Ruby have the same parent
smalltalk
I learn dynamic programming from Ruby
I learn block from Ruby
Obj-C is not difficult to learn.
Cocoa Framework is.
I learn UI inheritance from Flash/ActionScript
https://developer.apple.com/Library/ios/#docum Cocoa/Conceptual/CocoaFundamental CocoaDesignPatterns/CocoaDesignPattern
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/WhatIsCocoa/WhatIsCocoa.html
Essential ActionScript 3.0 p.459
event handling
async handling
cocos2d
But..
delegation
Obj-C is subset of C
memory management
retain v.s release
-(NSString *) getBookName { NSString *the_name = @"This is a
book"; return the_name; }
-(NSString *) getBookName { NSString *the_name = @"This is a
book"; [the_name release]; return the_name; }
autorelease http://blog.eddie.com.tw/2010/11/25/autorelease-in-objective-c/
-(NSString *) getBookName { NSString *the_name = @"This is a
book"; return [the_name autorelease]; }
None
ARC Automatic Reference Counting
ARC knows more Obj-C than you :)
new style Obj-C syntax
literal syntax sugar
NSNumber* age = [NSNumber numberWithInt:18];
NSNumber* age = @18;
NSNumber* pi = [NSNumber numberWithFloat:3.1415926F];
NSNumber* pi = @3.1415926F;
NSArray* kids = [NSArray arrayWithObjects:@"高思", @"高齊", nil];
NSArray* kids = @[@"高思", @"高齊"];
NSDictionary* kidsEnglishName = [NSDictionary dictionaryWithObjectsAndKeys: @"Kose", @"高思", @"Coach", @"高齊", nil];
NSDictionary* kidsEnglishName = @{@"高思":@"Kose", @"高齊":@"Coach"};
// for-loop style NSArray* kids = ... for (int i
= 0; i < kids.count; ++i) { NSString* kid = [kids objectAtIndex:i]; // do something }
// for-in style NSArray* kids = ... for (NSString* kid
in kids) { // do something }
// block style NSArray* kids = ... [kids enumerateObjectsUsingBlock:^(NSString* kid,
NSUInteger idx, BOOL *stop) { // do something here }];
NSDictionary * kidsEnglishName = ... NSArray* keys = [dict allKeys];
for (NSString* key in keys) { NSString* value = [dict objectForKey:key]; // do something else }
// block style NSDictionary * kidsEnglishName = ... [kids enumerateKeysAndObjectsUsingBlock:^(id
key, id obj, BOOL *stop) { // do something here }];
Subscripting Methods
NSArray* kids = @[@"高思", @"高齊"]; NSLog(@"%@", [kids objectAtIndex:0]); // 高思
NSArray* kids = @[@"高思", @"高齊"]; NSLog(@"%@", kids[0]); // 高思
NSMutableArray* kids = [@[@"高思", @"高齊"] mutableCopy]; kids[0] = @"狸貓"; NSLog(@"%@",
[kids objectAtIndex:0]); // 狸貓
NSMutableDictionary* kidsEnglishName = [@{@"高思":@"Kose", @"高齊":@"Coach"} mutableCopy]; kidsEnglishName[@"高思"] = @"Gauss";
@synthesize
// hello.h @property (nonatomic, strong) NSString* name; // hello.m @synthesize
name = _name;
// hello.h @property (nonatomic, strong) NSString* name; // hello.m @synthesize
name = _name;
None
Conclusion
there's no BEST or WORST language
non of them are useless
code more, complain less
完 thank you all :)
高見見龍龍 Conacts photo by Eddie Websie Blog Plurk Facebook Google
Plus Twiter 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://twiter.com/#!/eddiekao
[email protected]
+886-928-617-687