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
230
復習OptionSet
Tomohiro Nishimura
December 26, 2016
Tweet
Share
More Decks by Tomohiro Nishimura
See All by Tomohiro Nishimura
レガシーシステム洗い出し大作戦
sixeight
0
1.4k
我々のRealmはどこからやってくるのか
sixeight
1
340
まだ見ぬAPIに思いを馳せて
sixeight
0
110
今年読んだまんが
sixeight
0
210
べんりな検索ワード
sixeight
0
220
Readable Width in action
sixeight
0
160
UIPreviewInteraction: Overview
sixeight
1
590
Accessing the Music Library
sixeight
1
2.6k
Web APIについての雑談
sixeight
0
390
Other Decks in Technology
See All in Technology
contenteditableと向き合う
kikuchikakeru
2
290
サプライチェーン攻撃に備える
ryunen344
0
160
スタッフエンジニアの道: The Staff Engineer’s Path
snoozer05
PRO
41
13k
20240911_New_Relicダッシュボード活用例
speakerdeckfk
0
100
なぜクラウドサービスで Web コンソールを提供するのか
shuta13
4
2k
AI活用したくてもできなかった不動産SaaSの今とこれから
nealle
0
260
Autonomous Database Serverless 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
15
40k
スーパーマリオRPGのリメイク版の変更点からみるUX
nishiharatsubasa
1
330
DevRelの始め方
moongift
PRO
1
280
ロボットアームを遠隔制御の話 & LLMをつかったIoTの話もしたい
soracom
PRO
1
270
エンジニア視点で見る、 組織で運用されるデザインシステムにするには
shunya078
1
300
技術ブログや登壇資料を秒で作るコツ伝授します
minorun365
PRO
23
5.5k
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
242
11k
Happy Clients
brianwarren
96
6.6k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
43
2k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
354
29k
Teambox: Starting and Learning
jrom
131
8.7k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
190
16k
Making Projects Easy
brettharned
113
5.8k
Building Applications with DynamoDB
mza
90
6k
Large-scale JavaScript Application Architecture
addyosmani
508
110k
Six Lessons from altMBA
skipperchong
26
3.3k
The Cult of Friendly URLs
andyhume
76
6k
Robots, Beer and Maslow
schacon
PRO
157
8.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)
Α͍͓Λ