Slide 1

Slide 1 text

FOVN BT0QUJPO 6/21 potatotips #52 taiki komaba(@r_plus)

Slide 2

Slide 2 text

UBJLJLPNBCB !S@QMVT

Slide 3

Slide 3 text

0QUJPO4FU

Slide 4

Slide 4 text

CJUຖʹΦϓγϣϯΛׂ౰ͯΔ ΦϓγϣϯͷͨΊͷ΋ͷͬΆ͍

Slide 5

Slide 5 text

public extension DispatchQueue { public struct Attributes : OptionSet { public let rawValue: UInt64 public init(rawValue: UInt64) { self.rawValue = rawValue } public static let concurrent = Attributes(rawValue: 1<<1) @available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) public static let initiallyInactive = Attributes(rawValue: 1<<2) … 'PVOEBUJPOͰ΋ Α͘࢖ΘΕ͍ͯΔ https://github.com/apple/swift/blob/master/stdlib/public/SDK/Dispatch/Queue.swift

Slide 6

Slide 6 text

struct ShippingOptions: OptionSet { let rawValue: Int static let nextDay = ShippingOptions(rawValue: 1 << 0) static let secondDay = ShippingOptions(rawValue: 1 << 1) static let priority = ShippingOptions(rawValue: 1 << 2) static let standard = ShippingOptions(rawValue: 1 << 3) } ࣮૷͢Δͱ͜͏ͳΔ

Slide 7

Slide 7 text

self.doSomething(arg, option: [.nextDay, .priority]) … func doSomething(_ arg: Any, option: ShippingOptions) { … } ࢖͏ଆ͸͜͏

Slide 8

Slide 8 text

func doSomething(_ arg: Any, option: ShippingOptions) { if option.contains(.nextDay) { … } if option.contains(. secondDay) { … } } ͰɺͲͷΦϓγϣϯ͕ࢦఆ͞Ε͔ͨͰ ڍಈΛม͑Δʜ

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

ͳΜ͔Φϓγϣϯ൑ఆ͍͚ͨͩ͠ʹͯ͠͸ هड़͕໘౗͡Όͳ͍ʁ struct ShippingOptions: OptionSet { let rawValue: Int static let nextDay = ShippingOptions(rawValue: 1 << 0) static let secondDay = ShippingOptions(rawValue: 1 << 1) static let priority = ShippingOptions(rawValue: 1 << 2) static let standard = ShippingOptions(rawValue: 1 << 3) }

Slide 11

Slide 11 text

struct ShippingOptions: OptionSet { let rawValue: Int static let nextDay = ShippingOptions(rawValue: 1 << 0) static let secondDay = ShippingOptions(rawValue: 1 << 1) static let priority = ShippingOptions(rawValue: 1 << 2) static let standard = ShippingOptions(rawValue: 1 << 3) } ͳΜ͔Φϓγϣϯ൑ఆ͍͚ͨͩ͠ʹͯ͠͸ هड़͕໘౗͡Όͳ͍ʁ ͜ͷ͋ͨΓ͕ɻ

Slide 12

Slide 12 text

FOVNͰ΍ͬͯΈΑ͏

Slide 13

Slide 13 text

0QUJPOఆٛˠγϯϓϧFOVN enum ShippingOptions { case nextDay case secondDay case priority case standard }

Slide 14

Slide 14 text

self.doSomething(arg, option: .nextDay) … func doSomething(_ arg: Any, option: ShippingOptions) { … } ࢖͏ଆ͕͜͏

Slide 15

Slide 15 text

͜ͷ··ͩͱ ෳ਺Φϓγϣϯࢦఆ͕ग़དྷͳ͍ͷͰʜ

Slide 16

Slide 16 text

Մม௕Ҿ਺ ʢ7BSJBEJD1BSBNFUFSTʣ

Slide 17

Slide 17 text

͜͏ͩͬͨͷΛ self.doSomething(arg, option: .nextDay) … func doSomething(_ arg: Any, option: ShippingOptions) { … }

Slide 18

Slide 18 text

self.doSomething(arg, option: .nextDay, . priority) … Մม௕ʹ͢Δ func doSomething(_ arg: Any, option: ShippingOptions…) {…}

Slide 19

Slide 19 text

func doSomething(_ arg: Any, option: ShippingOptions…) { if option.contains(.nextDay) { … } if option.contains(. secondDay) { … } } ࣮૷ଆʹ͸"SSBZ͕དྷΔͷͰมߋͳ͠

Slide 20

Slide 20 text

·ͱΊ ϝιουͷΦϓγϣϯΛ ؆୯ʹఆ͍͚ٛͨͩ͠Ͱ͋Ε͹ΞϦͳͷͰ͸

Slide 21

Slide 21 text

͓ΘΓɻ