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
iOS app Development - Block
Search
高見龍
April 15, 2014
Programming
160
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
iOS app Development - Block
高見龍
April 15, 2014
More Decks by 高見龍
See All by 高見龍
宅宅自以為的浪漫:跟 AI 一起為自己辦的研討會寫一個售票系統
eddie
0
620
自己的售票系統自己做!
eddie
0
630
AI Agent 時代的開發者生存指南
eddie
4
2.7k
print("Hello, World")
eddie
2
660
為你自己學 Python - 冷知識篇
eddie
1
470
為你自己學 Python
eddie
0
780
Generative AI 年會小聚 - AI 教我寫程式
eddie
0
230
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
780
AI 時代的程式語言學習法
eddie
0
280
Other Decks in Programming
See All in Programming
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
520
自作OSでスライド発表する
uyuki234
1
3.8k
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
270
【やさしく解説 設計編 #1】「ドメイン駆動」と「実装駆動」ってなに? 〜設計の考え方を、たとえ話で学ぼう〜
panda728
PRO
1
120
初めてのKubernetes 本番運用でハマった話
oku053
0
130
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
210
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
190
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
210
5分で問診!Composer セキュリティ健康診断
codmoninc
0
270
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
1
260
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
230
Featured
See All Featured
Speed Design
sergeychernyshev
33
1.9k
The Pragmatic Product Professional
lauravandoore
37
7.4k
Everyday Curiosity
cassininazir
0
260
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
340
The Cult of Friendly URLs
andyhume
79
6.9k
Leo the Paperboy
mayatellez
8
1.9k
Design in an AI World
tapps
1
260
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
510
It's Worth the Effort
3n
188
29k
Making Projects Easy
brettharned
120
6.7k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
Mind Mapping
helmedeiros
PRO
1
280
Transcript
iOS App Development Lesson 15 - Block Eddie Kao
define a block int (^myAdd)(int, int); myAdd = ^(int a1,
int a2) { return a1 + a2; };
define a block int (^myAdd)(int, int) = ^(int a1, int
a2) { return a1 + a2; };
call a block myAdd(2, 3);
no return type and params void (^myBlock)(void) = ^(void) {
NSLog(@"Hello, Block"); }; myBlock();
no return type and params (cont.) void (^myBlock)() = ^{
NSLog(@"Hello, Block"); }; myBlock();
get variable out of the block int mutiplier = 10;
int (^myAdd)(int, int) = ^(int a1, int a2) { return (a1 + a2) * mutiplier; };
define type for block typedef int (^MyBlockType) (int, int); MyBlockType
myAddType = ^(int a1, int a2) { return a1 + a2; };
return value to block typedef void (^CompleteBlock) (NSString* title, NSString*
author); typedef void (^FailBlock) (NSError* error); @interface DemoClass : NSObject - (void) fetchBookWithID:(NSInteger) bookID complete:(CompleteBlock) complete fail:(FailBlock) fail; @end @implementation DemoClass - (void) fetchBookWithID:(NSInteger)bookID complete:(CompleteBlock)complete fail:(FailBlock)fail { if (/.. something error.. /) { fail(error); } else { complete(@"This is a book", @"eddie kao"); } } @end
return value to block (cont.) DemoClass* demo = [[DemoClass alloc]
init]; [demo fetchBookWithID:10 complete:^(NSString *title, NSString *author) { NSLog(@"book title = %@, and author = %@", title, author); } fail:^(NSError *error) { NSLog(@"error = %@", error); }];
for-in v.s block enumeration NSArray* array = @[@1, @2, @3,
@4, @5]; for (id obj in array) { NSLog(@"%@", obj); } [array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSLog(@"%@", obj); }];
replace delegation with block
UIAnimation, the old way - (void)viewDidLoad { [super viewDidLoad]; UIView*
myView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)]; myView.backgroundColor = [UIColor redColor]; [self.view addSubview:myView]; [UIView beginAnimations:@"Demo" context:nil]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(endAnimationHandler)]; [UIView setAnimationDuration:3]; myView.alpha = 0; [UIView commitAnimations]; } - (void) endAnimationHandler { NSLog(@"animation end!"); }
UIAnimation, the block way - (void)viewDidLoad { [super viewDidLoad]; UIView*
myView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)]; myView.backgroundColor = [UIColor redColor]; [self.view addSubview:myView]; [UIView animateWithDuration:3 animations:^{ myView.alpha = 0; } completion:^(BOOL finished) { NSLog(@“animation end!”); }]; }
So, Why not use Block?
and Why use Block?
Keeps code together
and Apple says so!