Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
アプリが動いたその先へ (iOS アプリ開発編)
Search
Yuka Ezura
August 18, 2017
Programming
1
960
アプリが動いたその先へ (iOS アプリ開発編)
Yuka Ezura
August 18, 2017
Tweet
Share
More Decks by Yuka Ezura
See All by Yuka Ezura
Mastering share sheet preview
ezura
4
1.3k
SF Symbols
ezura
9
1.2k
気遣いの iOS プログラミング
ezura
11
3.4k
Secret Swift tour
ezura
7
2.8k
Swift Album ver.4.1
ezura
3
1.4k
Swift と Kotlin
ezura
4
2.6k
哲学とSwiftの発表
ezura
5
580
Blending Kotlin's culture into Swift
ezura
1
1.2k
Re: エラーと警告でコードをデザインする
ezura
2
950
Other Decks in Programming
See All in Programming
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
120
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
150
Djangoの開発環境で工夫したこと - pre-commit / DevContainer
hiroki_yod
1
650
Develop iOS apps with Neovim / vimconf_2024
uhooi
1
320
Haze - Real time background blurring
chrisbanes
1
430
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
210
Symfony Mapper Component
soyuka
2
510
Missing parts when designing and implementing Android UI
ericksli
0
390
Cursorでアプリケーションの追加開発や保守をどこまでできるか試したら得るものが多かった話
drumnistnakano
0
280
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
130
.NET Conf 2024の振り返り
tomokusaba
0
200
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
330
Featured
See All Featured
Six Lessons from altMBA
skipperchong
27
3.5k
Docker and Python
trallard
41
3.1k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
160
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Optimizing for Happiness
mojombo
376
70k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
250
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
480
Git: the NoSQL Database
bkeepers
PRO
427
64k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Transcript
ΞϓϦ͕ಈ͍ͨͦͷઌ (iOS ΞϓϦ։ൃฤ) 2017/8/18 ezura
“\(self)” • iOS engineer @ LINE • ֶੜ࣌: Android, iOS
engineer • Swift, Objective-C, Kotlin, Java, … ezura (@eduraaa)
୭ͩͬͯ࠷ॳॳ৺ऀ
ίʔυΛͬͯష͚ͬͯͬͭͯͨ͘Βɺ ΞϓϦ͕Ͱ͖͍ͯͨ ( 'ω')
Α͘Θ͔Βͳ͍ͱ͜Ζ͋Δ͚Ͳɺ ΞϓϦ͕Ͱ͖͍ͯͨ ( 'ω') retain…, delegate…, tableView…, ฒྻॲཧ…
ͳΜ͔ϝϞϦϦʔΫ͚ͯͨ͠Ͳɺ ΞϓϦ͕Ͱ͖͍ͯͨ ( 'ω') ࠭ͷ͓ͷΑ͏ͳίʔυ…
ϓϩͱͯ͠ஏ͔ͣ͘͠ͳ͍ɺ ΞϓϦΛ࡞Γ͍ͨ ( 'ω') Ͳ͏͢Εྑ͍ΜͩΖ͏…
ॳ৺ऀͷͱ͖ٙͩͬͨ͜ͱɺΜͰͨ͜ͱ Α͘ฉ࣭͘ weak ͱ strong ͷ͍͚ thread ཧͬͯ ݁ہͲ͏͢Εྑ͍ͷʁ งғؾͰ
thread Λ ͍ͬͯΔ ॥ࢀরා͍ Ͳ͏͢Ε͛Δͷʁ ࣗͷϓϩάϥϜͷ࣭ͬͯ ࣮ࡍʹͲͷϨϕϧͳͷ… ຊμϝͳ͜ͱΛ ͍ͬͯΔͷͰ… storyboard ͬͨํ͕ྑ͍ͷʁ
ݪଇɾݪཧ (جૅ) ঢ়گ + = ͑
ࠜຊతͳ෦Λ͓͞Β͍͠ͳ͕Β ٙΛղܾ͍ͯ͜͠͏ త
index • ࢀরपΓ • thread पΓ • ͦͷଞͷ͜ͱͰ࣭ɾ૬ஊ
ࢀরɾϝϞϦपΓ
॥ࢀরΛͲ͏͛ྑ͍ͷʁ
weak ͱ strong ͷ͍͚ʁ
ͦͦɺstrong ͱ͔ weak ͷࢦఆ ͳͥඞཁʁʁ
ΦϒδΣΫτΛ࡞Δ ↓ ΦϒδΣΫτͷσʔλΛஔ͍͓ͯ͘ॴ͕ඞཁ ↓ ΦϒδΣΫτͷσʔλΛஔ͍͓ͯ͘ॴΛϝϞϦ্ʹ֬อ͓ͯ͘͠ object
ΦϒδΣΫτΛ࡞Δ ↓ ΦϒδΣΫτͷσʔλΛஔ͍͓ͯ͘ॴ͕ඞཁ ↓ ΦϒδΣΫτͷσʔλΛஔ͍͓ͯ͘ॴΛϝϞϦ্ʹ֬อ͓ͯ͘͠ memory object
ΦϒδΣΫτΛ࡞Δ ↓ ΦϒδΣΫτͷσʔλΛஔ͍͓ͯ͘ॴ͕ඞཁ ↓ ΦϒδΣΫτͷσʔλΛஔ͍͓ͯ͘ॴΛϝϞϦ্ʹ֬อ͓ͯ͘͠ object memory
͍ͭɺ֬อͨ͠ྖҬΛղ์͢Εྑ͍ʁʁ object memory
͍ͭɺ֬อͨ͠ϝϞϦΛղ์͢Εྑ͍ʁʁ object memory object object ͏ೖΒͳ͍… མͪΑ…( ˘ω˘) object
object memory object object ͏ೖΒͳ͍… མͪΑ…( ˘ω˘) ͍ͭɺ֬อͨ͠ϝϞϦΛղ์͢Εྑ͍ʁʁ ↓ ΦϒδΣΫτ͕ෆཁʹͳͬͨͱ͖
object
“ཁΒͳ͍” ͬͯɺͲ͏ͬͯஅ͢Εྑ͍ʁ
ϝϞϦͷཧ • Java, Ruby, JavaScript, … • ํ๏: Garbage Collection
• Ͳ͔͜Βࢀর͞Εͳ͘ͳͬͨΦϒδΣΫτΛ GC ͕ௐͯղ์ (ਓ͕ཧ͠ͳ͍) • Swift, Objective-C • ํ๏: Reference Counting • ඞཁͳΒΧϯτΛ૿͠ɺཁΒͳ͘ͳͬͨΒΧϯτΛݮΒ͢ Χϯτ͕ 0 ʹͳͬͨΒෆཁͱΈͳͯ͠ղ์ (Reference Count = ΦϒδΣΫτΛඞཁͱ͍ͯ͠Δͷ)
Reference Counting • Swift, Objective-C • ARC (Automatic Reference Counting)
• weak ࢀরͱ strong ࢀর • Objective-C (ੲ) • MRC (Manual Reference Counting) • [obj retain] ͱ͔ॻ͍ͯ͋ͬͨΒ͜Ε
Reference Counting • Swift, Objective-C • ARC (Automatic Reference Counting)
• weak ࢀরͱ strong ࢀর • Objective-C (ੲ) • MRC (Manual Reference Counting) • [obj retain] ͱ͔ॻ͍ͯ͋ͬͨΒ͜Ε
Reference Count • ΦϒδΣΫτΛ࡞Γ·ͨ͠ object
Reference Count • ΦϒδΣΫτΛ࡞Γ·ͨ͠ • strong ࢀর͍ͯ͠Δม͕͋Γ·͢ object strong let
obj = object ࢀরΧϯτ += 1 => 1
Reference Count object strong let obj = object ࢀরΧϯτ -=
1 => 0 • ΦϒδΣΫτΛ࡞Γ·ͨ͠ • strong ࢀর͍ͯ͠Δม͕͋Γ·͢ • strong ࢀর͍ͯ͠Δม͕ͳ͘ͳΓ·ͨ͠
Reference Count • ΦϒδΣΫτΛ࡞Γ·ͨ͠ • strong ࢀর͍ͯ͠Δม͕͋Γ·͢ • strong ࢀর͍ͯ͠Δม͕ͳ͘ͳΓ·ͨ͠
• ΦϒδΣΫτղ์͞Ε·͢ object strong let obj = object ࢀরΧϯτ => 0
Reference Count • ΦϒδΣΫτΛ࡞Γ·ͨ͠ object
Reference Count • ΦϒδΣΫτΛ࡞Γ·ͨ͠ • strong ࢀর͍ͯ͠Δม͕͋Γ·͢ object strong let
obj = object ࢀরΧϯτ += 1 => 1
Reference Count object strong let obj = object ࢀরΧϯτ
=> 1 weak var obj = object • ΦϒδΣΫτΛ࡞Γ·ͨ͠ • strong ࢀর͍ͯ͠Δม͕͋Γ·͢ • weak ࢀর͍ͯ͠Δม͕͋Γ·͢
Reference Count • ΦϒδΣΫτΛ࡞Γ·ͨ͠ • strong ࢀর͍ͯ͠Δม͕͋Γ·͢ • weak ࢀর͍ͯ͠Δม͕͋Γ·͢
• weak ࢀর͍ͯ͠Δม͕ͳ͘ͳΓ·ͨ͠ object strong let obj = object ࢀরΧϯτ => 1 weak var obj = object
Reference Count • ΦϒδΣΫτΛ࡞Γ·ͨ͠ • strong ࢀর͍ͯ͠Δม͕͋Γ·͢ • weak ࢀর͍ͯ͠Δม͕͋Γ·͢
• weak ࢀর͍ͯ͠Δม͕ͳ͘ͳΓ·ͨ͠ object strong let obj = object ࢀরΧϯτ => 1
Reference Count object strong let obj = object ࢀরΧϯτ +=
1 => 1 weak var obj = object • ΦϒδΣΫτΛ࡞Γ·ͨ͠ • strong ࢀর͍ͯ͠Δม͕͋Γ·͢ • weak ࢀর͍ͯ͠Δม͕͋Γ·͢
Reference Count object strong let obj = object ࢀরΧϯτ -=
1 => 0 weak var obj = object • ΦϒδΣΫτΛ࡞Γ·ͨ͠ • strong ࢀর͍ͯ͠Δม͕͋Γ·͢ • weak ࢀর͍ͯ͠Δม͕͋Γ·͢ • strong ࢀর͍ͯ͠Δม͕ͳ͘ͳΓ·ͨ͠
Reference Count object strong let obj = object ࢀরΧϯτ =>
0 weak var obj = object • ΦϒδΣΫτΛ࡞Γ·ͨ͠ • strong ࢀর͍ͯ͠Δม͕͋Γ·͢ • weak ࢀর͍ͯ͠Δม͕͋Γ·͢ • strong ࢀর͍ͯ͠Δม͕ͳ͘ͳΓ·ͨ͠ • ΦϒδΣΫτղ์͞Ε·͢
Reference Count object strong let obj = object ࢀরΧϯτ =>
0 weak var obj = object • ΦϒδΣΫτΛ࡞Γ·ͨ͠ • strong ࢀর͍ͯ͠Δม͕͋Γ·͢ • weak ࢀর͍ͯ͠Δม͕͋Γ·͢ • strong ࢀর͍ͯ͠Δม͕ͳ͘ͳΓ·ͨ͠ • ΦϒδΣΫτղ์͞Ε·͢ : nil ͕ೖ͞ΕΔΘ͚Ͱͳ͍
ࢀর strong var obj objA strong var obj objB
ࢀর strong var obj = objB objA strong var obj
= objA objB
ࢀর strong var obj = objB objA strong var obj
= objA objB
ࢀর strong var obj = objB objA strong var obj
= objA objB ॥ࢀর
ࢀর strong var obj = objB objA strong var obj
= objA objB Ͳ͏ͨ͠Βղ์͞ΕΔʁ
ࢀর strong var obj = nil objA strong var obj
= objA objB ໌ࣔతʹࢀরΛղ͘ඞཁ͕͋Δ
ࢀর strong var obj = nil objA strong var obj
= objA objB Auto ͱҰମ… :(
ࢀর strong var obj = nil objA strong var obj
= objA objB ʮͺͬͱݟΘ͔Βͳ͍͚Ͳɺ~͠ͳ͍ͱ͍͚ͳ͍ʯ ͷΑ͏ͳɺ҉తྃղͷ͋Δίʔυ͍͔ͭഁ໓͢Δ
ࢀর strong var obj = objB objA strong var obj
= objA objB
ࢀর strong var obj = objB objA weak var obj
= objA objB
ࢀর strong var obj = objB objA weak var obj
= objA objB
ࢀর strong var obj = objB objA weak var obj
= objA objB
ࢀর strong var obj = objB objA weak var obj
= objA objB
ཧతʹΘ͔͚ͬͨͲɺ Ͳ͏͍͚Εྑ͍ͷʁ Object ؒͷؔੑ͔ΒܾΊΑ͏
ࢀর strong var obj = objB objA weak var obj
= objA objB
ParentViewController ChildViewController strong var cvc = cvc weak var delegate
= ChildViewController pvc ParentViewController
ParentViewController ChildViewController strong var cvc = cvc weak var delegate
= ChildViewController pvc ParentViewController
ParentViewController ChildViewController strong var cvc = cvc weak var delegate
= ChildViewController pvc ParentViewController
ParentViewController ChildViewController strong var cvc = cvc weak var delegate
= ChildViewController pvc ParentViewController
ParentViewController ChildViewController strong var cvc = cvc weak var delegate
= ChildViewController pvc ParentViewController
ParentViewController ChildViewController strong var cvc = cvc weak var delegate
= ChildViewController pvc ParentViewController ParentViewController ͕͍ͳ͘ͳͬͨΒɺ ChildViewController ͍Βͳ͘ͳΔؔ
weak ͱ strong ͷ͍͚ʁ Object ؒͷؔੑ͔ΒܾΊΑ͏
॥ࢀরΛͲ͏͛ྑ͍ͷʁ લड़ͷ weak, strong ͷ͍͚ closure ʹΑΔΩϟϓνϟʹؾΛ͚ͭΔ
ࢀর strong var obj = objB objA strong var obj
= objA objB
ࢀর object closure object
ࢀর closure object object
ࢀর closure object object ΩϟϓνϟϦετ [weak self]
༨ஊ closure object object ΩϟϓνϟϦετ [weak self]
༨ஊ closure object object ΩϟϓνϟϦετ [weak self]
༨ஊ closure object object ΩϟϓνϟϦετ [weak self]
༨ஊ closure object object
༨ஊ closure object object
༨ஊ closure object object
༨ஊ closure object object
༨ஊ closure object object
1 weak ʹ͖͢ʁ strong ʹ͖͢ʁ class ViewController: UIViewController {
@IBOutlet /* weak? strong? */ var label: UILabel! … }
1 ͲͪΒՄೳ (ঢ়گʹΑΔ͚ΕͲɺ`weak` ͕ద͢Δ߹͕ଟ͍) class ViewController: UIViewController { @IBOutlet
/* weak? strong? */ var label: UILabel! … }
1 view viewController view sub views strong
1 view viewController view sub views weak
1 view viewController view sub views weak
1 view viewController view sub views weak
1 view viewController view sub views strong
1 view viewController view sub views strong
1 view viewController view sub views strong
1 view viewController view sub views strong
1 view viewController view sub views weak memory warning
ൃੜ࣌ʹ view Λഁغ͢Δ߹͕͋ΔͷͰɺ weak ͷํ͕߹ͳ߹͕ଟ͍
1 view viewController view sub views strong vc ͕ࣗڧ͘ґଘ͍ͯ͠ΔͳΒɺ
strong Ͱྑ͍߹͋Δ
1 view viewController view sub views weak vc.view ͕શʹ໋ΛѲΔͳΒ
weak ͕ద͍ͯ͠Δ
1 view viewController view sub views weak vc.view ͕શʹ໋ΛѲΔͳΒ
weak ͕ద͍ͯ͠Δ
1 view viewController view sub views weak vc.view ͕શʹ໋ΛѲΔͳΒ
weak ͕ద͍ͯ͠Δ
thread
Thread ͱʁ
• UIViewController ࡞ͯ͠ • Λઃఆͯ͠ • ͦΕΛදࣔ Λઃఆ ViewController
࡞ දࣔ
DispatchQueue.main.async { // σʔλΛදࣔ } Λઃఆ ViewController ࡞ දࣔ
• UIViewController ࡞ͯ͠ • Λઃఆͯ͠ • ͦΕΛදࣔ • αʔό͔ΒσʔλΛͱ͖ͬͯͯ • σʔλΛදࣔ αʔόͱ௨৴ σʔλΛදࣔ thread thread
thread • thread of execution • single thread (Լਤ) ը૾Λ
ը໘ΛΓସ͑Δ λοϓ͞Εͨ σʔλΛอଘ ड৴ͪ μϯϩʔυ࢝ΊΔ ड৴த εΫϩʔϧ
thread • thread of execution • multi thread (Լਤ) ը૾Λදࣔ͢Δ
ը໘ΛΓସ͑Δ λοϓ͞Εͨ σʔλΛอଘ ड৴ͪ μϯϩʔυ࢝ΊΔ ड৴த εΫϩʔϧ
iOS Ͱͷૢ࡞ • GCD • NSOperation • thread Λѻ͏
(͋·ΓΒͳ͍) • (Rx ͷϝιουͰࢦఆ) DispatchQueue.global().async { <#code#> }
iOS Ͱͷ thread • main thread • 1 ͚ͭͩ (ΞϓϦىಈ࣌ʹ࡞͞ΕΔ)
• sub thread • ෳଘࡏՄೳ • ௨৴ॲཧɺDB ૢ࡞ͷॏ͍ॲཧϩάΛૹ৴͢ΔͳͲͷॲཧ
“UI ͷૢ࡞ main thread ͰΖ͏”
main thread Ҏ֎ͰͬͨΒͲ͏ͳΔͷʁ
Ͳ͏͍͏ͱ͖ɺ ͦΕΛҧͯ͠͠·͏ͷʁ
main thread ͬͯɺ Կऀʁ
main thread • ΞϓϦىಈ࣌ʹ࡞͞ΕΔ • Run loop ͕ճ͍ͬͯΔ • ΠϕϯτΛϋϯυϦϯά
• λοϓ͞ΕͨͳͲͷ UI Πϕϯτ • ϥΠϑαΠΫϧ (ىಈͨ͠ɺ෮ؼͨ͠ɺ…) • දࣔͷߋ৽ • …
Run loop on main thread Πϕϯτདྷͳ͍͔ͳ
Run loop on main thread Πϕϯτདྷͳ͍͔ͳ
Run loop on main thread Πϕϯτདྷͳ͍͔ͳ λοϓͨ͠ʂ
Run loop on main thread དྷͨʂ View ʹ௨ͯ͠ ఆٛ͞Εͯͨಈ࡞Λͯ͠… ΠϕϯτͷͨΊͷશͯͷॲཧΛͨ͠Β
Run loop on main thread Πϕϯτདྷͳ͍͔ͳ Πϕϯτདྷͳ͍͔ͳ
͠ɺॏ͍ॲཧΛ main thread ͰΔͱ ௨৴։࢝ ௨৴ͬͯΔ DB ʹอଘ …
͠ɺॏ͍ॲཧΛ main thread ͰΔͱ ௨৴։࢝ ௨৴ͬͯΔ DB ʹอଘ … λοϓͨ͠ʂ
͠ɺॏ͍ॲཧΛ main thread ͰΔͱ ௨৴։࢝ ௨৴ͬͯΔ DB ʹอଘ … λοϓͨ͠ʂ
͝ΊΜɺ͍͠…
main thread • ΞϓϦىಈ࣌ʹ࡞͞ΕΔ • Run loop ͕ճ͍ͬͯΔ • ΠϕϯτΛϋϯυϦϯά
• λοϓ͞ΕͨͳͲͷ UI Πϕϯτ • ϥΠϑαΠΫϧ (ىಈͨ͠ɺ෮ؼͨ͠ɺ…) • දࣔͷߋ৽ • …
“UI ͷૢ࡞ main thread ͰΖ͏”
1 @IBAction func buttonDidTap(_ sender: UIButton) { label.text =
"Changed" label.textColor = .red sleep(2) view.backgroundColor = .green } 1.Label ͷ৭ͱςΩετΛมߋ 2.2 ඵؒ sleep 3.എܠ৭Λมߋ
1 (͑) @IBAction func buttonDidTap(_ sender: UIButton) { label.text
= "Changed" label.textColor = .red sleep(2) view.backgroundColor = .green } 1. 2 ඵؒ Ϣʔβͷૢ࡞Λड͚͚ͳ͍ 2. Label ͱ എܠͷද͕ࣔಉ࣌ʹมΘΔ
Πϕϯτͪ ը໘ͷߋ৽ λοϓ͞Εͨ = Ϣʔβ༝དྷͷૢ࡞ λοϓ͞Εͨͱ͖ͷॲཧ (func buttonDidTap) 1
(ղઆ) Πϕϯτͪ main thread
2 @IBAction func buttonDidTap(_ sender: UIButton) { DispatchQueue.global().async {
[label = label] in label?.text = "Changed" label?.textColor = .red } view.backgroundColor = .green } 1.sub thread Ͱ Label Λมߋ 2.main thread ͰഎܠΛมߋ
2 (͑) @IBAction func buttonDidTap(_ sender: UIButton) { DispatchQueue.global().async
{ [label = label] in label?.text = "Changed" label?.textColor = .red } view.backgroundColor = .green } ෆఆͷಈ࡞
Πϕϯτͪ main loop ը໘ͷߋ৽ λοϓ͞Εͨ = Ϣʔβ༝དྷͷૢ࡞ λοϓ͞Εͨͱ͖ͷॲཧ (func buttonDidTap)
view ͷഎܠߋ৽ 2 (ղઆ) label ͷ text Λมߋ label ͷେ͖͞Λߋ৽ ؔ࿈͢Δ view ͷஔΛ࠶ܭࢉ label ͷ৭Λมߋ … main thread sub thread
3 override func viewDidLoad() { super.viewDidLoad() NotificationCenter.default .addObserver(forName: .notificationKey,
object: nil, queue: nil) { _ in // ᶃ } } ᶃ Ͳͷ thread Ͱಈ͘ʁ
3 (͑) NotificationCenter.default ɹɹɹɹɹɹɹ .post(name: .notificationKey, ɹɹɹɹɹɹɹɹɹɹɹɹɹ object: nil)
notification Λൃߦͨ͠ thread
“UI ͷૢ࡞ main thread ͰΖ͏”
main thread Ҏ֎ͰͬͨΒͲ͏ͳΔͷʁ ෆఆͷಈ࡞ Ϋϥογϡ͢ΔՄೳੑ͋Δ
Ͳ͏͍͏ͱ͖ɺ ͦΕΛҧͯ͠͠·͏ͷʁ sub thread Ͱ UI Λૢ࡞͢ΔॲཧΛ࣮ߦͨ͠ͱ͖ * UI Λૢ࡞͢ΔॲཧΛؚΜͰ͍Δ
function Λ sub thread Ͱ࣮ߦ * UI Λૢ࡞͢ΔॲཧΛؚΉ closure Λ sub thread Ͱ࣮ߦ * didSet ʹ UI Λૢ࡞͢ΔॲཧΛؚΜͰ͍ΔϓϩύςΟʹ sub thread Ͱೖॲཧ࣮ߦ * Rx Ͱɺ͍ͭͷؒʹ͔ sub thread Ͱ࣮ߦ͞ΕΔΑ͏ʹͳ͍ͬͯͨ ͳͲͳͲ
͙ํ๏ʁ • UI ͷૢ࡞ΛؚΉ͜ͱΛ໊લίϝϯτͰ໌ࣔ͢Δ • sub thread Ͱ࣮ߦ͍ͯͯ͠ɺUI Λૢ࡞ͨ͘͠ͳͬͨΒɺGCD Λͬͯ
main thread Ͱ࣮ߦ͢ΔΑ͏ʹ੍ޚ • Xcode9 Ͱ UI ͷૢ࡞Λ sub thread ্Ͱ࣮ߦ͍ͯ͠Δͱܯࠂͯ͘͠ΕΔػೳ͕ ͋Δ
main thread ͬͯɺ Կऀʁ • UI ΠϕϯτͷϋϯυϦϯάͷׂ • ΞϓϦͷϥΠϑαΠΫϧͷ௨ •
وॏͳϦιʔε (͍͠ͱΞϓϦ͕ΧΫͭ͘ݪҼʹͳΔ)
·ͱΊ • ͋ΘͯͣɺجૅΛʹ͚ͭΔͱਊ͔Βڧ͘ͳΕΔ • weak, strong ͷ͍͚ • ΦϒδΣΫτؒͷؔੑ͔Βߟ͑ͯΈΑ͏ •
thread • main thread ্Ͱ UI ૢ࡞ • function closure ݺͼग़͞Εͨ thread ্Ͱ࣮ߦ͞ΕΔͷΛ ೦಄ʹஔ͍ͯɺ࣮ߦ࣌ͷঢ়گΛ૾ͯ͠ΈΑ͏
Q&A