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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
高見龍
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
590
自己的售票系統自己做!
eddie
0
620
AI Agent 時代的開發者生存指南
eddie
4
2.7k
print("Hello, World")
eddie
2
650
為你自己學 Python - 冷知識篇
eddie
1
460
為你自己學 Python
eddie
0
760
Generative AI 年會小聚 - AI 教我寫程式
eddie
0
220
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
760
AI 時代的程式語言學習法
eddie
0
270
Other Decks in Programming
See All in Programming
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
2
660
「エンジニアインターン、どうやって取った?」準備のリアルを語るLT会 Progate BAR
akiomatic
0
130
LLM Plugin for Node-REDの利用方法と開発について
404background
0
170
TAKTでAI駆動開発の品質を設計する
j5ik2o
6
1.2k
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
190
技術記事、 専門家としてのプログラマ、 言語化
mizchi
11
4.3k
AIチームを指揮するOSS「TAKT」活用術 / How to Use “TAKT,” an OSS Tool for Orchestrating AI Teams
nrslib
6
880
Vite+ Unified Toolchain for the Web
naokihaba
0
280
net-httpのHTTP/2対応について
naruse
0
470
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2k
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
230
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
510
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Test your architecture with Archunit
thirion
1
2.3k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
320
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
940
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
170
Side Projects
sachag
455
43k
Scaling GitHub
holman
464
140k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
360
GitHub's CSS Performance
jonrohan
1033
470k
Google's AI Overviews - The New Search
badams
0
1k
Site-Speed That Sticks
csswizardry
13
1.2k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
270
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!