Slide 1

Slide 1 text

Վ෣ب࠲.tech#11 Swiftϓϩάϥϛϯάษڧձ LT(3)

Slide 2

Slide 2 text

Who am I? MAGES. Inc. Game Div. iOS Developer @lovee

Slide 3

Slide 3 text

ϋοΧιϯ GCD

Slide 4

Slide 4 text

ϋοΧιϯʹ࢖͏ Swift ϋοΧιϯ͸͍͍ͧɻ

Slide 5

Slide 5 text

ϋοΧιϯ஌Βͳ͍ਓʁ

Slide 6

Slide 6 text

ϋοΧιϯࢀՃͨ͜͠ͱ͋Δਓʁ

Slide 7

Slide 7 text

ϋοΧιϯͰ৆औͬͨ͜ͱ͋Δਓʁ

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

ϋοΧιϯʹඞཁͳ΋ͷ े෼ʹ଎͍Ϛγϯ • the New MacBook Ͱ΋े෼ ৴པͰ͖Δ஥ؒ •஥ؒɺେࣄɻͱͯ΋େࣄ ޮ཰ߴ͍Ξ΢τϓοτ •24࣌ؒલޙ͔͕࣌ؒ͠ͳ͍ ંΕͳ͍৺ˡ͜Εॏཁ •ϋοΧιϯʹϋϓχϯά͸͖ͭ΋ͷ

Slide 10

Slide 10 text

ޮ཰ߴ͍Ξ΢τϓοτ ։ൃ։࢝લͷίʔσΟϯά͸ېࢭ OSS ͷ Library ΍ Framework ͸ར༻Մ ͦ͏ͩɺࣗ෼ͷ Framework Λ࡞Ζ͏ɻ

Slide 11

Slide 11 text

Swift ͷಛ௃ Extension ରԠʹΑΔߴ͍֦ுੑ ීஈࣗ෼͕Α͘࢖͏ϝιουΛ Framework ʹ·ͱΊͪΌ͓͏

Slide 12

Slide 12 text

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)

Slide 13

Slide 13 text

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) } }

Slide 14

Slide 14 text

var array = [Int](0 ..< 5) //[0, 1, 2, 3, 4] ͋Εʁ γϟοϑϧͬͯ Ͳ͏΍ΔΜ͚ͩͬʁ

Slide 15

Slide 15 text

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]

Slide 16

Slide 16 text

var array = [Int](0 ..< 5) //[0, 1, 2, 3, 4] array.shuffle() //[1, 4, 0, 2, 3] // Extension extension Array { public var shuffled: Array { 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 } }

Slide 17

Slide 17 text

https://github.com/el-hoshino/Eltaso

Slide 18

Slide 18 text

Thank you

Slide 19

Slide 19 text

Swift 3.0 ͷ GCD ࠓ·Ͱͷ GCD ͷྺ࢙ͷதͰ࠷େͷϦϦʔε

Slide 20

Slide 20 text

GCDʢdispatch_…ʣΛ஌Βͳ͍ਓʁ

Slide 21

Slide 21 text

ࠓ·Ͱ… ಉظॲཧʗඇಉظॲཧ 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#>)

Slide 22

Slide 22 text

͜Ε͔Β DispatchObject Ͱॲཧ͢Δ͜ͱʹ DispatchQueue DispatchSemaphore DispatchTime DispatchWorkItem …

Slide 23

Slide 23 text

let imageView = UIImageView() let image = UIImage() //... dispatch_async(dispatch_get_main_queue()) { imageView.image = image }

Slide 24

Slide 24 text

let imageView = UIImageView() let image = UIImage() //... DispatchQueue.main.async { imageView.image = image }

Slide 25

Slide 25 text

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") }

Slide 26

Slide 26 text

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") }

Slide 27

Slide 27 text

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") }

Slide 28

Slide 28 text

ৄ͘͠͸ https://developer.apple.com/ reference/dispatch ·Ͱ

Slide 29

Slide 29 text

dispatch_once ͸͓๢͘ͳΓʹ… ୅ΘΓʹ static lazy var ͳͲΛ׆༻͠Ζͱͷ͜ͱ

Slide 30

Slide 30 text

Thank you