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
480
ハッカソンに使う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
個人アプリを2年ぶりにアプデしたから褒めて / I just updated my personal app, praise me!
lovee
0
360
How did I build an Open-Source SwiftUI Toast Library
lovee
1
72
SwiftUIで使いやすいToastの作り方 / How to build a Toast system which is easy to use in SwiftUI
lovee
3
810
SwiftUIで二重スクロール作ってみた / When I tried to make a dual-scroll-ish view in SwiftUI
lovee
1
280
Observation のあれこれ / A brief introduction about Observation
lovee
3
360
ChatGPT 時代の勉強 / Learning under ChatGPT era
lovee
27
8.6k
属人化しない為の勉強会作り / To make tech meetups with less personal dependencies
lovee
0
300
偏見と妄想で語るスクリプト言語としての Swift / Swift as a Scripting Language
lovee
2
830
danger-swift-kantoku
lovee
1
520
Other Decks in Programming
See All in Programming
『テスト書いた方が開発が早いじゃん』を解き明かす #phpcon_nagoya
o0h
PRO
8
2.4k
React 19アップデートのために必要なこと
uhyo
8
1.4k
5分で理解する SOLID 原則 #phpcon_nagoya
shogogg
1
300
XStateを用いた堅牢なReact Components設計~複雑なClient Stateをシンプルに~ @React Tokyo ミートアップ #2
kfurusho
1
980
Open source software: how to live long and go far
gaelvaroquaux
0
660
パスキーのすべて ── 導入・UX設計・実装の紹介 / 20250213 パスキー開発者の集い
kuralab
3
880
一休.com のログイン体験を支える技術 〜Web Components x Vue.js 活用事例と最適化について〜
atsumim
0
890
コードを読んで理解するko build
bells17
1
110
Grafana Loki によるサーバログのコスト削減
mot_techtalk
1
150
Kotlinの開発でも AIをいい感じに使いたい / Making the Most of AI in Kotlin Development
kohii00
5
1k
第3回関東Kaggler会_AtCoderはKaggleの役に立つ
chettub
3
1.1k
Bedrock Agentsレスポンス解析によるAgentのOps
licux
3
910
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
4
430
Faster Mobile Websites
deanohume
306
31k
GraphQLとの向き合い方2022年版
quramy
44
14k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Facilitating Awesome Meetings
lara
52
6.2k
Designing for Performance
lara
604
68k
Rails Girls Zürich Keynote
gr2m
94
13k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
GitHub's CSS Performance
jonrohan
1030
460k
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