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
enum as Option.
Search
r-plus
June 21, 2018
Technology
0
2.1k
enum as Option.
enum as Option.
potatotips #52
r-plus
June 21, 2018
Tweet
Share
More Decks by r-plus
See All by r-plus
Swizzling Swizzling Swizzling
r_plus
0
310
Image optimization for mobile on CDN
r_plus
0
580
Advanced guard of DeallocationChecker
r_plus
2
2.8k
東急ハンズの P2Pレジ間通信2018
r_plus
4
1.9k
Enterprise cert management.
r_plus
0
350
CircleCI 2.0 for macOS
r_plus
1
1.2k
carthage verify
r_plus
2
5.8k
業務アプリの切札 Programable KIOSK mode 大全
r_plus
0
4k
PropertyObserverとinoutでやらかした話
r_plus
1
1.2k
Other Decks in Technology
See All in Technology
DevFest 2024 Incheon / Songdo - Compose UI 조합 심화
wisemuji
0
160
マイクロサービスにおける容易なトランザクション管理に向けて
scalar
0
190
どちらを使う?GitHub or Azure DevOps Ver. 24H2
kkamegawa
0
1.2k
【re:Invent 2024 アプデ】 Prompt Routing の紹介
champ
0
160
事業貢献を考えるための技術改善の目標設計と改善実績 / Targeted design of technical improvements to consider business contribution and improvement performance
oomatomo
0
150
終了の危機にあった15年続くWebサービスを全力で存続させる - phpcon2024
yositosi
27
23k
宇宙ベンチャーにおける最近の情シス取り組みについて
axelmizu
0
120
Oracle Cloudの生成AIサービスって実際どこまで使えるの? エンジニア目線で試してみた
minorun365
PRO
4
300
組み込みアプリパフォーマンス格闘記 検索画面編
wataruhigasi
1
140
[トレノケ雲の会 mod.13] 3回目のre:Inventで気づいたこと -CloudOperationsを添えて-
shintaro_fukatsu
0
110
レンジャーシステムズ | 会社紹介(採用ピッチ)
rssytems
0
280
Working as a Server-side Engineer at LY Corporation
lycorp_recruit_jp
0
370
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
33
1.5k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Speed Design
sergeychernyshev
25
670
GraphQLとの向き合い方2022年版
quramy
44
13k
The Invisible Side of Design
smashingmag
298
50k
The World Runs on Bad Software
bkeepers
PRO
66
11k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Code Review Best Practice
trishagee
65
17k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
How STYLIGHT went responsive
nonsquared
96
5.2k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Transcript
FOVN BT0QUJPO 6/21 potatotips #52 taiki komaba(@r_plus)
UBJLJLPNBCB !S@QMVT
0QUJPO4FU
CJUຖʹΦϓγϣϯΛׂͯΔ ΦϓγϣϯͷͨΊͷͷͬΆ͍
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
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) } ࣮͢Δͱ͜͏ͳΔ
self.doSomething(arg, option: [.nextDay, .priority]) … func doSomething(_ arg: Any, option:
ShippingOptions) { … } ͏ଆ͜͏
func doSomething(_ arg: Any, option: ShippingOptions) { if option.contains(.nextDay) {
… } if option.contains(. secondDay) { … } } ͰɺͲͷΦϓγϣϯ͕ࢦఆ͞Ε͔ͨͰ ڍಈΛม͑Δʜ
None
ͳΜ͔Φϓγϣϯఆ͍͚ͨͩ͠ʹͯ͠ هड़͕໘͡Όͳ͍ʁ 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) }
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) } ͳΜ͔Φϓγϣϯఆ͍͚ͨͩ͠ʹͯ͠ هड़͕໘͡Όͳ͍ʁ ͜ͷ͋ͨΓ͕ɻ
FOVNͰͬͯΈΑ͏
0QUJPOఆٛˠγϯϓϧFOVN enum ShippingOptions { case nextDay case secondDay case priority
case standard }
self.doSomething(arg, option: .nextDay) … func doSomething(_ arg: Any, option: ShippingOptions)
{ … } ͏ଆ͕͜͏
͜ͷ··ͩͱ ෳΦϓγϣϯࢦఆ͕ग़དྷͳ͍ͷͰʜ
ՄมҾ ʢ7BSJBEJD1BSBNFUFSTʣ
͜͏ͩͬͨͷΛ self.doSomething(arg, option: .nextDay) … func doSomething(_ arg: Any, option:
ShippingOptions) { … }
self.doSomething(arg, option: .nextDay, . priority) … Մมʹ͢Δ func doSomething(_ arg:
Any, option: ShippingOptions…) {…}
func doSomething(_ arg: Any, option: ShippingOptions…) { if option.contains(.nextDay) {
… } if option.contains(. secondDay) { … } } ࣮ଆʹ"SSBZ͕དྷΔͷͰมߋͳ͠
·ͱΊ ϝιουͷΦϓγϣϯΛ ؆୯ʹఆ͍͚ٛͨͩ͠Ͱ͋ΕΞϦͳͷͰ
͓ΘΓɻ