Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
NDS36 Objective-C
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Shintaro Abe
March 11, 2014
Programming
1.6k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
NDS36 Objective-C
2014/03/15 NDS36 発表資料
Shintaro Abe
March 11, 2014
More Decks by Shintaro Abe
See All by Shintaro Abe
アルコールストーブの作り方
dictav
0
310
Swiftを少しだけ
dictav
0
310
Ruby
dictav
0
1.6k
Other Decks in Programming
See All in Programming
Androidだけじゃない、DroidKaigiで広がった私の技術スタック
akkeylab
0
120
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
370
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
150
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
450
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
270
ジョジョの世界をXRで再現する
mofurune
0
130
Simple Storage Service(S3) is not simple
iwatsukayura
0
210
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
350
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
190
Security issues being discussed on Web Platforms
petamoriken
0
1.4k
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
7
1.9k
Featured
See All Featured
Designing for humans not robots
tammielis
254
26k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
350
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
Prompt Engineering for Job Search
mfonobong
0
480
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
600
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
Transcript
OBJECTIVE-C 2014/03/15 SAT. NAGAOKA DEVELOPERS STUDY #36 DICTAV (SHINTARO ABE)
DICTAV • ৽ׁࢢࡏॅ IOSϓϩ άϥϚ
ϓϩάϥϛϯάݴޠྺ ߴઐॳظ HTML/C/Java/BASIC ߴઐதظ ߴઐ࣌ɺ ߴઐޙظ ߴઐͷଔͰແཧཧ ߴઐޙظ ߴઐͷޙഐʹ ࣗӴୂॳظ
MFC ࣗӴୂதظ JOVIAL ࣗӴୂޙظ Ruby ϑϦʔ Objective-C ࠷ۙ Go
OBJECTIVE-C #import <Foundation/Foundation.h> ! @interface MyObject : NSObject @end !
@implementation MyObject - (void) helloWorld { printf("Hello, World!\n"); } @end ! ! int main(int argc, char **argv) { id obj = [MyObject new]; [obj helloWorld]; ! return 0; }
OBJECTIVE-C ͱ • 1983ੜ·ΕʢC++ͱಉ͡ʣ • C ͷεʔύʔηοτ • C++: better
C • Objective-C: C & Object System • runtime + Foundation framework (+ AppKit)
MACઐ༻Ͱ͠ΐʁ • GNUStep ΛೖΕΕWindowsͰ͏͘͝ • Grand Central Dispatch • Blocks
• Clang + LLVM
GNUSTEP • ϓϩϓϥΠΤλϦͳιϑτΣΞͰ͋ͬͨ NEXTSTEP ΛϋοΫͨ͠ͷ͕࢝·Γ • NeXT(+Sun Microsystems)͕OPENSTEPͱͯ͠ެ։ • OPENSTEP༷ʹશޓͳϓϥοτϑΥʔϜ
• Cocoaʹਵ
ͲΜͳݴޠ • ΦϒδΣΫτࢦݴޠ • ΦϒδΣΫτͷϝιουݺͼग़͠[]Ͱғ·Εͨ ϝοηʔδࣜ
Ϋϥε @interface MyObject : NSObject @property (strong) NSString *username; -
(id)initWithName:(NSString*)name; - (void)helloToName:(NSString*)name; @end ! @implementation MyObject { NSString *myName; } - (id)initWithName:(NSString*)name { self = [super init]; myName = name return self; } - (void)helloToName:(NSString*)name { printf(“hello %s\n”, [name UTF8String]); } @end
Α͘͏Ϋϥε • id (Any) • NSString • NSNumber • NSArray
• NSDictionary • NSURL • NSURLConnection (NSURLSession) • NSOperationQueue
ຊਓ͕͓͖ͬͯ͘ ৽̏େɾOBJECTIVE-CϓϩάϥϛϯάελΠϧ • σϦήʔτ • Φϒαʔόʔ • ࢀরΧϯτํࣜ • ARC
: Automatic Reference Counting
σϦήʔτ • GoFຊͷAdapterύλʔϯ • UIपΓͰ͘׆༻͞Ε͍ͯΔ
σϦήʔτ @protocol DLDelegate <NSObject> - (NSURL*)nextURL; - (void)didFinishDownload:(id)object; @end !
@interface MyDownloader : NSObject @property (assign) id<DLDelegate> delegate @end ! @implementation MyDownloader - (void) downloadAsync { NSURL *url; while(url = [self.delegate nextURL]){ /* μϯϩʔυ*/ [self.delegate didFinishDownload:obj]; } } @end @interface MyObj:NSObject<DLDelegate> @end ! @implementation MyObject { MyDownloader *dw; } - (id)init { self = [super init]; dw = [MyDownloader new]; dw.delegate = self; [dw downloadAsync]; return self; } - (NSURL*)nextURL { NSURL *u = //… return u; } - (void) didFinishDownload:(id)obj { /* ޙॲཧ */ } @end
σϦήʔτ ϝΠϯ Ϋϩʔϥ URL͍ͩ͘͞ ը૾Ͳͧ
σϦήʔτ ϝΠϯ Ϋϩʔϥ URL͍ͩ͘͞ ը૾Ͳͧ Vim͖ URL͍ͩ͘͞ ը૾Ͳͧ Vim ͱ͔Α͔͘Βͳ͍
͠໘ͩͳ ͻΌͬ΄ʔ
σϦήʔτ @protocol DLDelegate <NSObject> - (NSURL*)nextURL; - (void)didFinishDownload:(id)object; @end !
@interface MyDownloader : NSObject @property (assign) id<DLDelegate> delegate @end ! @implementation MyDownloader - (void) downloadAsync { NSURL *url; while(url = [self.delegate nextURL]){ /* μϯϩʔυ*/ [self.delegate didFinishDownload:obj]; } } @end
Φϒαʔόʔ • GoFຊͷObserverύλʔϯ • ΦϒδΣΫτͷΠϯελϯεมΛࢹͯ͠ॲཧΛ ߦ͏
Φϒαʔόʔ @implementation Senshi - (id) init { self = [super
init]; [self addObserver: self forKeyPath: @“hitPoint” options: NSKeyValueObservingOptionInitial context: NULL]; return self; } ! - (void)observeValueForKeyPath:(NSString *)keyPath… { if ([keyPath isEqual:@“hitPoint”]) { /* Կ͔͢Δ */ } } ! - (void)damage:(NSInteger)damage { self.hitPoint = self.hitPoint - damage; } @end
Φϒαʔόʔ @implementation Souryo - (void) mimamoruSenshi:(Senshi*)senshi { [senshi addObserver: self
forKeyPath: @“hitPoint” options: NSKeyValueObservingOptionInitial context: NULL]; } ! - (void) observeValueForKeyPath:(NSString *)keyPath… { if ([keyPath isEqual:@“hitPoint”]) { /* ճ෮͢Δ */ } } @end
ࢀরΧϯτ - (void) hello:(NSString*)str { [str retain]; MyObject *obj =
[MyObject new]; ! /* Կ͔ॲཧ */ ! [obj release]; [str release]; } ! - (void) helloWorld { NSString *str = @“world”; [self hello:str]; [str release]; } ·͔͞ͷʂʂ ! ࢀরΧϯτํࣜ ϓϩάϥϛϯά
ࢀরΧϯτ - (void) hello:(NSString*)str { [str retain]; MyObject *obj =
[MyObject new]; ! /* Կ͔ॲཧ */ ! [obj release]; [str release]; } ! - (void) helloWorld { NSString *str = @“world”; [self hello:str]; [str release]; } ίϯύΠϥ͕ͬͯ͘ΕΔΑ͏ʹͳΓ ·ͨ͠ɻ
ࢀরΧϯτ - (void) hello:(NSString*)str { [str retain]; MyObject *obj =
[MyObject new]; ! /* Կ͔ॲཧ */ ! [obj release]; [str release]; } ! - (void) helloWorld { NSString *str = @“world”; [self hello:str]; [str release]; } - (void) hello:(NSString*)str { [str retain]; MyObject *obj = [MyObject new]; ! /* Կ͔ॲཧ */ ! [obj release]; [str release]; } ! - (void) helloWorld { NSString *str = @“world”; [self hello:str]; [str release]; }
Cͷ֦ு • Blocks • Grand Central Dispatch
BLOCKS // prepare void HelloWorld(void) { printf("Hello, World!\n"); } !
void DoFunc(void (*pfunc)()) { (*pfunc)(); } ! // main void main(void) { DoFunc(HelloWorld); }
BLOCKS // prepare void DoBlock(void (^block)(void)) { block(); } !
// main void main(void) { DoBlock(^{ printf(“Hello, World!\n”); }); }
BLOCKS // prepare void DoBlock10(void (^block)(int n)) { for (int
i=0; i < 10; i++) { block(i); } } ! // main void main(void) { DoBlock10(^(int n){ printf("Hello, Block %d!\n", n); }); }
GCD: GRAND CENTRAL DISPATCH “λεΫΛඇಉظʹ࣮ߦ͢Δٕज़ͷͻͱͭͱͯ͠ɺGrand Central DispatchʢGCDʣͱ͍͏ͷ͕͋Γ·͢ɻ௨ৗΞϓϦέʔγϣϯதʹ هड़͢ΔεϨουཧ༻ͷίʔυΛɺγεςϜϨϕϧͰ࣮ͨ͠ͷͰ ͢ɻ։ൃऀ͕͠ͳ͚ΕͳΒͳ͍ͷɺ࣮ߦ͍ͨ͠λεΫΛఆٛ͠ɺద ͳDispatch
QueueʹՃ͢Δ͜ͱ͚ͩͰ͢ɻ͢ΔͱGCDɺඞཁͳε ϨουΛੜ͠ɺͦ͜ͰλεΫΛ࣮ߦ͢ΔΑ͏దʹεέδϡʔϦϯά ͠·͢ɻεϨουཧ͕γεςϜͷҰ෦ͱͯ͠Έࠐ·Ε͍ͯΔͷͰɺ શମΛݟͯ͠λεΫΛཧɺ࣮ߦͰ͖ɺैདྷͷεϨουΑΓޮ͕ ্͠·͢ɻ” Excerpt From: “ฒྻϓϩάϥϛϯάΨΠυ” https://developer.apple.com/jp/devcenter/ios/library/ documentation/ConcurrencyProgrammingGuide.pdf
GCD // prepare dispatch_queue_priority_t priority; dispatch_queue_t queue; ! priority =
DISPATCH_QUEUE_PRIORITY_DEFAULT; queue = dispatch_get_global_queue(priority, 0); ! // main printf(“1,"); ! dispatch_async(queue, ^{ printf("3"); }); printf(“2,”); ! // results => 1,2,3
NSOPERATIONQUEUE // https://t.co/6LbHw8F9UU // prepare NSOperationQueue *queue; queue = [NSOperationQueue
new]; ! ! ! // main printf(“1,"); ! [queue addOperationWithBlock:^{ printf("3"); }]; printf(“2,”); ! // results => 1,2,3 // prepare dispatch_queue_priority_t priority; dispatch_queue_t queue; ! priority = DISPATCH_QUEUE_PRIORITY_DEFAULT; queue = dispatch_get_global_queue(priority,0); ! // main printf(“1,"); ! dispatch_async(queue, ^{ printf("3"); }); printf(“2,”); ! // results => 1,2,3
·ͱΊ • Objective-C Appleઐ༻ͷݴޠͰͳ͍Α • Blocks GCD Λ͏ͱ͜Ε·Ͱ໘ͩͬͨ C
ݴޠ ͷϓϩάϥϛϯά͕Ұ෦ָʹͳΔΑ • Overrideͱ͔͍͢͝ΏΔ͍͔Βڵຯ͋ΕͲ͏ͧ
ࠂ • ΞϓϦϦϦʔε • ͘͘ձ
ΞϓϦϦϦʔεʂ • ΞϓϦΛϦϦʔε͠·ͨ͠ਃதͰ͢ • ࠓΘΓͱՋͰ͢ • ̍ޙʹࣄͳ͘ͳΔ͔ɻΑΖ͓͘͠ئ͍͠·͢ɻ
৽ׁ͘͘ձͬͯ·͢ʂ • ݄̏͘Β͍Ͱ༵ʹʮ৽ׁ͘͘ձʯͬͯ· ͢ɻ • ࠷େ໊̔ऩ༰ՄೳɻࢀՃඅແྉʂ • ༵ʹՈʹ͍ͨ͘ͳ͍ਓͥͻ • ଞͷ༵ͷرͥͻ
• ษڧձ։͖͍ͨਓ͝૬ஊ͍ͩ͘͞
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠