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
Better Code Design in PHP
afilina
PRO
0
130
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
みんなでプロポーザルを書いてみた
yuriko1211
0
280
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
初めてDefinitelyTypedにPRを出した話
syumai
0
420
CSC509 Lecture 11
javiergs
PRO
0
180
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
230
CSC509 Lecture 13
javiergs
PRO
0
110
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
140
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
169
14k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Optimizing for Happiness
mojombo
376
70k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
KATA
mclloyd
29
14k
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