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
460
ハッカソンに使う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
SwiftUIで二重スクロール作ってみた / When I tried to make a dual-scroll-ish view in SwiftUI
lovee
1
170
Observation のあれこれ / A brief introduction about Observation
lovee
3
300
ChatGPT 時代の勉強 / Learning under ChatGPT era
lovee
20
6k
属人化しない為の勉強会作り / To make tech meetups with less personal dependencies
lovee
0
190
偏見と妄想で語るスクリプト言語としての Swift / Swift as a Scripting Language
lovee
2
640
danger-swift-kantoku
lovee
1
400
Decimal、正しく使ってる? / Are you using Decimal correctly?
lovee
4
570
A story about me trying to make a router that manages when, how and which view to transit in a SwiftUI app
lovee
1
320
M1チップの脆弱性M1raclesを読み解く / About the vulnerability on M1 chip called M1racles
lovee
2
1.5k
Other Decks in Programming
See All in Programming
とにかくHTTP3をライトニングに話す / Anyway, I'll talk to Lightning about HTTP3.
seike460
PRO
0
120
LLMチャットボットのアプリケーション設計Tips
os1ma
4
660
Prepare for Jakarta EE 11 - Performance and Developer Productivity
ivargrimstad
0
490
Parallel Socket Communication in Swift
s_shimotori
0
220
Honoとhtmx
yusukebe
6
1.2k
PHP8の機能を使って堅牢にコードを書く
fendo181
6
2.6k
生成 AI の中身を覗いてみよう〜基礎から医療現場での応用まで〜
soh9834
2
760
オブジェクト指向は必要なのか / Is object-oriented needed?
kishida
27
19k
両面どころかインフラもTSでできるよ ~ 全方位TypeScriptによるプロダクト開発 ~
myfinder
8
2.2k
Kotlinを用いたDSL的な設計手法と使用上の注意
kohii00
3
530
Material 3で Material 2ぽい見た目にする
numeroanddev
2
250
Go1.22からの疑似乱数生成器について/go-122-pseudo-random-generator
convto
1
160
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
407
22k
A designer walks into a library…
pauljervisheath
199
23k
Clear Off the Table
cherdarchuk
82
310k
Embracing the Ebb and Flow
colly
78
4.1k
Why Our Code Smells
bkeepers
PRO
330
56k
The Art of Programming - Codeland 2020
erikaheidi
40
12k
Making the Leap to Tech Lead
cromwellryan
123
8.4k
Why You Should Never Use an ORM
jnunemaker
PRO
50
8.6k
Producing Creativity
orderedlist
PRO
335
39k
Typedesign – Prime Four
hannesfritz
36
2k
StorybookのUI Testing Handbookを読んだ
zakiyama
10
4.5k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
153
14k
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