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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
690
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
ソフトウェアアーキテクトのための意思決定術: Create Decision Readiness—The Real Skill Behind Architectural Decision
snoozer05
PRO
27
8.3k
トラブルの大半は「言ってない」x「言ってない」じゃねーか!!
ichimichi
0
290
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
14k
マイグレーションガイドに書いてないRiverpod 3移行話
taiju59
0
340
【SLO】"多様な期待値" と向き合ってみた
z63d
2
290
Devinを導入したら予想外の人たちに好評だった
tomuro
0
800
Eight Engineering Unit 紹介資料
sansan33
PRO
1
6.9k
DX Improvement at Scale
ntk1000
2
120
Windows ネットワークを再確認する
murachiakira
PRO
0
230
問い合わせ自動化の技術的挑戦
recruitengineers
PRO
2
120
ヘルシーSRE
tk3fftk
2
220
クラウド時代における一時権限取得
krrrr38
1
150
Featured
See All Featured
Ruling the World: When Life Gets Gamed
codingconduct
0
160
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
79
How to Think Like a Performance Engineer
csswizardry
28
2.5k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
170
Optimising Largest Contentful Paint
csswizardry
37
3.6k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.8k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
130
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.6k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
300
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
280
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͕དྷΔͷͰมߋͳ͠
·ͱΊ ϝιουͷΦϓγϣϯΛ ؆୯ʹఆ͍͚ٛͨͩ͠Ͱ͋ΕΞϦͳͷͰ
͓ΘΓɻ