Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
My Way to Objective-C
Search
高見龍
November 22, 2012
Programming
6
640
My Way to Objective-C
高見龍
November 22, 2012
Tweet
Share
More Decks by 高見龍
See All by 高見龍
為你自己學 Python
eddie
0
550
Generative AI 年會小聚 - AI 教我寫程式
eddie
0
59
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
520
AI 時代的程式語言學習法
eddie
0
99
前端模組解放運動 - importmap
eddie
0
1.3k
Git 和 DevOps - 在混亂的流星群開發流程中找到小確幸
eddie
1
1.1k
模組化前端開發:從亂七八糟到組織有序
eddie
0
1.5k
被 Vue 框架耽誤的建置工具
eddie
2
980
開開心心寫測試,你的程式碼也會微笑
eddie
1
1.2k
Other Decks in Programming
See All in Programming
ファインディの テックブログ爆誕までの軌跡
starfish719
2
1.1k
iOSエンジニアから始める visionOS アプリ開発
nao_randd
3
120
技術を根付かせる / How to make technology take root
kubode
1
240
Grafana Loki によるサーバログのコスト削減
mot_techtalk
1
110
Flutter × Firebase Genkit で加速する生成 AI アプリ開発
coborinai
0
150
“あなた” の開発を支援する AI エージェント Bedrock Engineer / introducing-bedrock-engineer
gawa
11
1.8k
『GO』アプリ データ基盤のログ収集システムコスト削減
mot_techtalk
0
110
第3回関東Kaggler会_AtCoderはKaggleの役に立つ
chettub
3
890
[Fin-JAWS 第38回 ~re:Invent 2024 金融re:Cap~]FaultInjectionServiceアップデート@pre:Invent2024
shintaro_fukatsu
0
400
GitHub Actions × RAGでコードレビューの検証の結果
sho_000
0
240
2024年のkintone API振り返りと2025年 / kintone API look back in 2024
tasshi
0
210
いりゃあせ、PHPカンファレンス名古屋2025 / Welcome to PHP Conference Nagoya 2025
ttskch
1
270
Featured
See All Featured
Code Review Best Practice
trishagee
66
17k
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.4k
The Cult of Friendly URLs
andyhume
78
6.2k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.8k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.5k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.4k
Building Adaptive Systems
keathley
40
2.4k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
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