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
ハッカソンに使うSwift & Swift 3.0のGCD
Search
Elvis Shi
September 16, 2016
Programming
0
500
ハッカソンに使うSwift & Swift 3.0のGCD
A light-talk in 歌舞伎座.tech#11
Elvis Shi
September 16, 2016
Tweet
Share
More Decks by Elvis Shi
See All by Elvis Shi
Kotlin エンジニアへ送る:Swift 案件に参加させられる日に備えて~似てるけど色々違う Swift の仕様 / from Kotlin to Swift
lovee
1
260
個人アプリを2年ぶりにアプデしたから褒めて / I just updated my personal app, praise me!
lovee
0
460
How did I build an Open-Source SwiftUI Toast Library
lovee
1
100
SwiftUIで使いやすいToastの作り方 / How to build a Toast system which is easy to use in SwiftUI
lovee
3
970
SwiftUIで二重スクロール作ってみた / When I tried to make a dual-scroll-ish view in SwiftUI
lovee
1
310
Observation のあれこれ / A brief introduction about Observation
lovee
3
390
ChatGPT 時代の勉強 / Learning under ChatGPT era
lovee
27
8.8k
属人化しない為の勉強会作り / To make tech meetups with less personal dependencies
lovee
0
320
偏見と妄想で語るスクリプト言語としての Swift / Swift as a Scripting Language
lovee
2
870
Other Decks in Programming
See All in Programming
Blazing Fast UI Development with Compose Hot Reload (droidcon New York 2025)
zsmb
1
270
Cursor AI Agentと伴走する アプリケーションの高速リプレイス
daisuketakeda
1
130
エンジニア向け採用ピッチ資料
inusan
0
180
WindowInsetsだってテストしたい
ryunen344
1
210
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
250
Team operations that are not burdened by SRE
kazatohiei
1
290
関数型まつりレポート for JuliaTokai #22
antimon2
0
160
来たるべき 8.0 に備えて React 19 新機能と React Router 固有機能の取捨選択とすり合わせを考える
oukayuka
2
880
20250704_教育事業におけるアジャイルなデータ基盤構築
hanon52_
2
170
0626 Findy Product Manager LT Night_高田スライド_speaker deck用
mana_takada
0
130
なぜ適用するか、移行して理解するClean Architecture 〜構造を超えて設計を継承する〜 / Why Apply, Migrate and Understand Clean Architecture - Inherit Design Beyond Structure
seike460
PRO
1
710
Modern Angular with Signals and Signal Store:New Rules for Your Architecture @enterJS Advanced Angular Day 2025
manfredsteyer
PRO
0
170
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
A better future with KSS
kneath
239
17k
Making Projects Easy
brettharned
116
6.3k
Mobile First: as difficult as doing things right
swwweet
223
9.7k
Writing Fast Ruby
sferik
628
62k
Balancing Empowerment & Direction
lara
1
390
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
48
5.4k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
Navigating Team Friction
lara
187
15k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
5
230
Transcript
Վب࠲.tech#11 Swiftϓϩάϥϛϯάษڧձ LT(3)
Who am I? MAGES. Inc. Game Div. iOS Developer @lovee
ϋοΧιϯ GCD
ϋοΧιϯʹ͏ Swift ϋοΧιϯ͍͍ͧɻ
ϋοΧιϯΒͳ͍ਓʁ
ϋοΧιϯࢀՃͨ͜͠ͱ͋Δਓʁ
ϋοΧιϯͰऔͬͨ͜ͱ͋Δਓʁ
None
ϋοΧιϯʹඞཁͳͷ ेʹ͍Ϛγϯ • the New MacBook Ͱे ৴པͰ͖Δؒ •ؒɺେࣄɻͱͯେࣄ ޮߴ͍Ξτϓοτ
•24࣌ؒલޙ͔͕࣌ؒ͠ͳ͍ ંΕͳ͍৺ˡ͜Εॏཁ •ϋοΧιϯʹϋϓχϯά͖ͭͷ
ޮߴ͍Ξτϓοτ ։ൃ։࢝લͷίʔσΟϯάېࢭ OSS ͷ Library Framework ར༻Մ ͦ͏ͩɺࣗͷ Framework
Λ࡞Ζ͏ɻ
Swift ͷಛ Extension ରԠʹΑΔߴ͍֦ுੑ ීஈ͕ࣗΑ͘͏ϝιουΛ Framework ʹ·ͱΊͪΌ͓͏
var id = UIDevice.current.identifierForVendor?.description ?? “" let remainingIndex = id.characters.index(id.startIndex,
offsetBy: 8, limitedBy: id.endIndex) ?? id.endIndex id = id.substring(to: remainingIndex)
var id = UIDevice.current.identifierForVendor?.description ?? “" id.keepFirst(8) // Extension extension
String { public func keepingFirst(_ n: Int = 1) -> String { let remainingIndex = self.characters.index(self.startIndex, offsetBy: n, limitedBy: self.endIndex) ?? self.endIndex return self.substring(to: remainingIndex) } } extension String { public mutating func keepFirst(_ n: Int = 1) { self = self.keepingFirst(n) } }
var array = [Int](0 ..< 5) //[0, 1, 2, 3,
4] ͋Εʁ γϟοϑϧͬͯ Ͳ͏ΔΜ͚ͩͬʁ
var array = [Int](0 ..< 5) //[0, 1, 2, 3,
4] // Fisher-Yates Shuffle Algorithm for i in array.indices.reversed().dropLast() { let j = Int(arc4random_uniform(UInt32(i))) (array[i], array[j]) = (array[j], array[i]) } //[1, 4, 0, 2, 3]
var array = [Int](0 ..< 5) //[0, 1, 2, 3,
4] array.shuffle() //[1, 4, 0, 2, 3] // Extension extension Array { public var shuffled: Array<Element> { var array = self for i in array.indices.reversed().dropLast() { let j = Int(arc4random_uniform(UInt32(i))) (array[i], array[j]) = (array[j], array[i]) } return array } public mutating func shuffle() { self = self.shuffled } }
https://github.com/el-hoshino/Eltaso
Thank you
Swift 3.0 ͷ GCD ࠓ·Ͱͷ GCD ͷྺ࢙ͷதͰ࠷େͷϦϦʔε
GCDʢdispatch_…ʣΛΒͳ͍ਓʁ
ࠓ·Ͱ… ಉظॲཧʗඇಉظॲཧ dispatch_sync(<#dispatch_queue_t#>, <#() -> Void#>) dispatch_async(<#dispatch_queue_t#>, <#() -> Void#>)
ϝΠϯΩϡʔʗάϩʔόϧΩϡʔ dispatch_get_main_queue() dispatch_get_global_queue(<#Int#>, <#UInt#>) ηϚϑΥ dispatch_semaphore_create(<#Int#>) dispatch_semaphore_signal(<#dispatch_semaphore_t#>) dispatch_semaphore_wait(<#dispatch_semaphore_t#>, <#dispatch_time_t#>)
͜Ε͔Β DispatchObject Ͱॲཧ͢Δ͜ͱʹ DispatchQueue DispatchSemaphore DispatchTime DispatchWorkItem …
let imageView = UIImageView() let image = UIImage() //... dispatch_async(dispatch_get_main_queue())
{ imageView.image = image }
let imageView = UIImageView() let image = UIImage() //... DispatchQueue.main.async
{ imageView.image = image }
let semaphore = dispatch_semaphore_create(0) dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY, 0)) { //Data Downloading... dispatch_semaphore_signal(semaphore)
} let waitTime = dispatch_time(DISPATCH_TIME_NOW, Int64(NSEC_PER_SEC) * 60) if dispatch_semaphore_wait(semaphore, waitTime) == 0 { print(“Succeeded") } else { print("Failed") }
let semaphore = DispatchSemaphore(value: 0) DispatchQueue.global().async { //... semaphore.signal() }
let waitTime = DispatchTime.now() + DispatchTimeInterval.seconds(60) if semaphore.wait(timeout: waitTime) == .success { print("Succeeded") } else { print("Failed") }
let semaphore = DispatchSemaphore(value: 0) DispatchQueue.global().async { //... semaphore.signal() }
let waitTime = DispatchTime.now() + .seconds(60) if semaphore.wait(timeout: waitTime) == .success { print("Succeeded") } else { print("Failed") }
ৄ͘͠ https://developer.apple.com/ reference/dispatch ·Ͱ
dispatch_once ͓͘ͳΓʹ… ΘΓʹ static lazy var ͳͲΛ׆༻͠Ζͱͷ͜ͱ
Thank you