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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
高見龍
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
630
自己的售票系統自己做!
eddie
0
650
AI Agent 時代的開發者生存指南
eddie
4
2.8k
print("Hello, World")
eddie
2
670
為你自己學 Python - 冷知識篇
eddie
1
490
為你自己學 Python
eddie
0
790
Generative AI 年會小聚 - AI 教我寫程式
eddie
0
240
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
790
AI 時代的程式語言學習法
eddie
0
290
Other Decks in Programming
See All in Programming
170k Jobs a Day on GKE: Scaling Mercari's CI Platform - and What's Next for AI-Native Development
junyaokabe
0
110
TSX の <Hoge<Fuga>> という構文に驚いた話 / tsx-type-argument-syntax
kanaru0928
0
230
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
330
いまどきの Codex で開発する visionOS アプリの開発スタイルについて
karad
0
150
MySQLとPostgreSQLって何が違うの?
akagami
0
100
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
660
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
210
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
1
700
今さら聞けない .NET CLI
htkym
0
200
Google Apps Script で Ruby を動かす
kawahara
0
280
Android CLI
fornewid
0
220
yield再入門 #phpcon
o0h
PRO
0
1.2k
Featured
See All Featured
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.8k
How to build a perfect <img>
jonoalderson
1
5.9k
Optimising Largest Contentful Paint
csswizardry
37
3.9k
HDC tutorial
michielstock
2
790
Agile that works and the tools we love
rasmusluckow
331
22k
Building Applications with DynamoDB
mza
96
7.2k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
390
A Tale of Four Properties
chriscoyier
163
24k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
490
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
870
Context Engineering - Making Every Token Count
addyosmani
9
1.1k
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!