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 アプリ開発編)
Search
Yuka Ezura
August 18, 2017
Programming
1
950
アプリが動いたその先へ (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.3k
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
940
Other Decks in Programming
See All in Programming
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.4k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
110
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
230
Quine, Polyglot, 良いコード
qnighy
4
640
Click-free releases & the making of a CLI app
oheyadam
2
110
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
4
640
Jakarta EE meets AI
ivargrimstad
0
130
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.7k
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
200
Featured
See All Featured
A Philosophy of Restraint
colly
203
16k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Agile that works and the tools we love
rasmusluckow
327
21k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Typedesign – Prime Four
hannesfritz
40
2.4k
A designer walks into a library…
pauljervisheath
203
24k
It's Worth the Effort
3n
183
27k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.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