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
300
Image optimization for mobile on CDN
r_plus
0
560
Advanced guard of DeallocationChecker
r_plus
2
2.7k
東急ハンズの P2Pレジ間通信2018
r_plus
4
1.9k
Enterprise cert management.
r_plus
0
340
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
TypeScript、上達の瞬間
sadnessojisan
48
14k
データプロダクトの定義からはじめる、データコントラクト駆動なデータ基盤
chanyou0311
3
350
Why App Signing Matters for Your Android Apps - Android Bangkok Conference 2024
akexorcist
0
130
Next.jsとNuxtが混在? iframeでなんとかする!
ypresto
1
140
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
430
rootlessコンテナのすゝめ - 研究室サーバーでもできる安全なコンテナ管理
kitsuya0828
3
390
Terraform Stacks入門 #HashiTalks
msato
0
360
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
310
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
130
Application Development WG Intro at AppDeveloperCon
salaboy
0
200
組織成長を加速させるオンボーディングの取り組み
sudoakiy
2
220
Featured
See All Featured
Designing for Performance
lara
604
68k
GitHub's CSS Performance
jonrohan
1030
460k
What's new in Ruby 2.0
geeforr
343
31k
Building Adaptive Systems
keathley
38
2.3k
Writing Fast Ruby
sferik
627
61k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Designing the Hi-DPI Web
ddemaree
280
34k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Making Projects Easy
brettharned
115
5.9k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
130
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͕དྷΔͷͰมߋͳ͠
·ͱΊ ϝιουͷΦϓγϣϯΛ ؆୯ʹఆ͍͚ٛͨͩ͠Ͱ͋ΕΞϦͳͷͰ
͓ΘΓɻ