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
復習OptionSet
Search
Tomohiro Nishimura
December 26, 2016
Technology
0
210
復習OptionSet
Tomohiro Nishimura
December 26, 2016
Tweet
Share
More Decks by Tomohiro Nishimura
See All by Tomohiro Nishimura
レガシーシステム洗い出し大作戦
sixeight
0
1.3k
我々のRealmはどこからやってくるのか
sixeight
1
300
まだ見ぬAPIに思いを馳せて
sixeight
0
97
今年読んだまんが
sixeight
0
210
べんりな検索ワード
sixeight
0
210
Readable Width in action
sixeight
0
140
UIPreviewInteraction: Overview
sixeight
1
590
Accessing the Music Library
sixeight
1
2.5k
Web APIについての雑談
sixeight
0
390
Other Decks in Technology
See All in Technology
自動生成を活用した、運用保守コストを抑える Error/Alert/Runbook の一元集約管理 / Centralized management of Error/Alert/Runbook to minimize operational costs using automated code generation
biwashi
10
2.2k
Discord とビルダー&チャットボットの使い方 / How to use Discord and Builder & Chatbots
ks91
PRO
0
130
DevOpsメトリクスとアウトカムの接続にトライ!開発プロセスを通して計測できるメトリクスの活用方法
ham0215
2
200
Terraformあれやこれ/terraform-this-and-that
emiki
7
610
Java EE/Jakarta EEの現状と将来―クラウドネイティブ時代にJava EEは対応できるのか?―
takakiyo
1
100
Databricks におけるデータエンジニアリング
databricksjapan
0
380
Autonomous Database Cloud 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
14
35k
ここが嬉しいABAC ここが辛いよABAC #再解説+補足編
masahirokawahara
1
240
「共通基盤」を超えよ! 今、Platform Engineeringに取り組むべき理由
jacopen
25
5.9k
「手動オペレーションに定評がある」と言われた私が心がけていること / phpcon_odawara2024
blue_goheimochi
2
320
Reducing Cross-Zone Egress at Spotify with Custom gRPC Load Balancing Recap
koh_naga
0
150
人間の尊厳、幸福、アクセシビリティ / 第116回「WEB TOUCH MEETING」アクセシビリティSP
nulabinc
PRO
2
180
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
242
12k
Mobile First: as difficult as doing things right
swwweet
216
8.6k
GraphQLとの向き合い方2022年版
quramy
31
12k
The Art of Programming - Codeland 2020
erikaheidi
41
12k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
29
6k
StorybookのUI Testing Handbookを読んだ
zakiyama
11
4.6k
Teambox: Starting and Learning
jrom
128
8.4k
Rebuilding a faster, lazier Slack
samanthasiow
72
8.2k
BBQ
matthewcrist
80
8.7k
Git: the NoSQL Database
bkeepers
PRO
422
63k
Testing 201, or: Great Expectations
jmmastey
27
6.3k
How to train your dragon (web standard)
notwaldorf
72
5.1k
Transcript
෮श0QUJPO4FU ؔϞόΠϧΞϓϦݚڀձ
JE4JYFJHIU w ג ͯͳΞϓϦέʔγϣϯΤϯδχΞ w ۙگ w יϏʔϧͱ͍͏ΠϕϯτͰ࣌ؒҿΈଓ͚ ͨΒඓਫ͕ࢭ·Βͳ͘ͳΓ·ͨ͠
None
0QUJPO4FU
త w Ϣʔβʔ͕ૢ࡞ՄೳͳॲཧΛࢦఆ͢Δ w ྫ͑ w ಡΜͰ͍͍͚Ͳɺॻ͖ࠐΉࣄͰ͖ͳ͍ͱ͔ w ฤूͰ͖Δ͚Ͳɺ৽ن࡞Ͱ͖ͳ͍ͱ͔
&OVNFSBUJPO enum Permission { case read case create case edit
case delete }
&OVNFSBUJPO let permissions: [Permission] = [.read, .create] func read() {
guard permissions.contains(.read) else { forbidden() return } showReadViewController() }
&OVNFSBUJPO w ϦιʔεͷύʔϛογϣϯͱϢʔβʔͷݖݶ w ͜ͷϦιʔεʹରͯ͜͠ͷϢʔβʔ͕Մೳͳૢ࡞ ͳΜͳͷ͔ w ͞Βʹάϧʔϓຖʹݖݶ͕͋ͬͨΓ͢Δͱʜ let resourcePermissions:
[Permission] = [.read] let userPermissions: [Permission] = [.read, .create, .edit, .delete] resourcePermissions.filter { permission in return userPermissions.contains(permission) }
None
#JUXJTFPQFSBUJPO // _ _ _ _ delete edit create read
// 0 0 0 0 1 1 1 1 struct Permission { static let read: UInt8 = 0b00000001 static let create: UInt8 = 0b00000010 static let edit: UInt8 = 0b00000100 static let delete: UInt8 = 0b00001000 } 6*OUʹ໊લ͚ͭΔͱྑͦ͞͏ʜ
#JUXJTFPQFSBUJPO let permissions: UInt8 = Permission.read | Permission.create func read()
{ guard (permissions & Permission.read) != 0 else { forbidden() return } showReadViewController() }
#JUXJTFPQFSBUJPO w ͜ͷϦιʔεʹରͯ͜͠ͷϢʔβʔ͕Մೳͳૢ࡞ ͳΜͳͷ͔ let resource: UInt8 = Permission.read let
user: UInt8 = Permission.read | Permission.create | Permission.edit | Permission.delete let currentPermission = resource & user
None
0QUJPO4FU struct Permission: OptionSet { let rawValue: UInt8 static let
read = Permission(rawValue: 1 << 0) static let create = Permission(rawValue: 1 << 1) static let edit = Permission(rawValue: 1 << 2) static let delete = Permission(rawValue: 1 << 3) }
0QUJPO4FU let permissions: Permission = [.read, .create] func read() {
guard permissions.contains(.read) else { forbidden() return } showReadViewController() }
4FU"MHFCSB func contains(Self) func insert(Self) func update(with: Self) func remove(Self)
func union(Self) func intersection(Self) func symmetricDifference(Self) func formUnion(Self) func formIntersection(Self) func formSymmetricDifference(Self)
4FU"MHFCSB let p: Permission = [.read, .create, .edit] let o:
Permission = [.edit, .delete] p //=> 0111 o //=> 1100 p.union(o) //=> 1111 p.intersection(o) //=> 0100 p.symmetricDifference(o) //=> 1011
0QUJPO4FU w ͜ͷϦιʔεʹରͯ͜͠ͷϢʔβʔ͕Մೳͳૢ࡞ ͳΜͳͷ͔ let resource: Permission = [.read] let
user: Permission = [.read, .create, .edit, .delete] let current: Permission = resource.intersection(user)
None
Γ͍ͨ if case Permission.read = userPermission { print("Can read") }
Γ͍ͨ switch userPermission { case Permission.read: print("Can Read") fallthrough case
Permission.create: print("Can Create") fallthrough case Permission.edit: print("Can edit") fallthrough case Permission.delete: print("Can delete") }
dPQFSBUPS extension Permission { static func ~=(lhs: Permission, rhs: Permission)
-> Bool { return rhs.contains(lhs) } }
None
༇շͳؒͨͪ
༇շͳؒͨͪ w 6*$POUSPM4UBUF w OPSNBM w EJTBCMFE w FUDʜ button.setTitle("དྷ",
for: .normal) button.setTitle("ؔϞό", for: [.highlighted, .selected]) button.setTitle("ΑΖ͘͠", for: .disabled)
Α͍͓Λ