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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
r-plus
June 21, 2018
Technology
0
2.3k
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
420
Image optimization for mobile on CDN
r_plus
0
680
Advanced guard of DeallocationChecker
r_plus
2
3.2k
東急ハンズの P2Pレジ間通信2018
r_plus
4
2.2k
Enterprise cert management.
r_plus
0
400
CircleCI 2.0 for macOS
r_plus
1
1.3k
carthage verify
r_plus
2
5.9k
業務アプリの切札 Programable KIOSK mode 大全
r_plus
0
4.3k
PropertyObserverとinoutでやらかした話
r_plus
1
1.3k
Other Decks in Technology
See All in Technology
Claude_CodeでSEOを最適化する_AI_Ops_Community_Vol.2__マーケティングx_AIはここまで進化した.pdf
riku_423
2
480
20260204_Midosuji_Tech
takuyay0ne
0
120
広告の効果検証を題材にした因果推論の精度検証について
zozotech
PRO
0
120
顧客との商談議事録をみんなで読んで顧客解像度を上げよう
shibayu36
0
180
Agile Leadership Summit Keynote 2026
m_seki
1
500
茨城の思い出を振り返る ~CDKのセキュリティを添えて~ / 20260201 Mitsutoshi Matsuo
shift_evolve
PRO
1
200
CDKで始めるTypeScript開発のススメ
tsukuboshi
1
330
GSIが複数キー対応したことで、俺達はいったい何が嬉しいのか?
smt7174
3
140
インフラエンジニア必見!Kubernetesを用いたクラウドネイティブ設計ポイント大全
daitak
0
330
AWS Network Firewall Proxyを触ってみた
nagisa53
0
140
GitLab Duo Agent Platform × AGENTS.md で実現するSpec-Driven Development / GitLab Duo Agent Platform × AGENTS.md
n11sh1
0
120
コスト削減から「セキュリティと利便性」を担うプラットフォームへ
sansantech
PRO
3
1.3k
Featured
See All Featured
KATA
mclloyd
PRO
34
15k
How to Ace a Technical Interview
jacobian
281
24k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
1
49
The browser strikes back
jonoalderson
0
360
Optimising Largest Contentful Paint
csswizardry
37
3.6k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
110
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
220
Building Applications with DynamoDB
mza
96
6.9k
Into the Great Unknown - MozCon
thekraken
40
2.2k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
380
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͕དྷΔͷͰมߋͳ͠
·ͱΊ ϝιουͷΦϓγϣϯΛ ؆୯ʹఆ͍͚ٛͨͩ͠Ͱ͋ΕΞϦͳͷͰ
͓ΘΓɻ