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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Tomohiro Nishimura
December 26, 2016
Technology
0
290
復習OptionSet
Tomohiro Nishimura
December 26, 2016
Tweet
Share
More Decks by Tomohiro Nishimura
See All by Tomohiro Nishimura
レガシーシステム洗い出し大作戦
sixeight
0
1.7k
我々のRealmはどこからやってくるのか
sixeight
1
410
まだ見ぬAPIに思いを馳せて
sixeight
0
150
今年読んだまんが
sixeight
0
240
べんりな検索ワード
sixeight
0
270
Readable Width in action
sixeight
0
190
UIPreviewInteraction: Overview
sixeight
1
630
Accessing the Music Library
sixeight
1
2.9k
Web APIについての雑談
sixeight
0
410
Other Decks in Technology
See All in Technology
Introduction to Sansan, inc / Sansan Global Development Center, Inc.
sansan33
PRO
0
3k
Master Dataグループ紹介資料
sansan33
PRO
1
4.4k
どこで打鍵するのが良い? IaCの実行基盤選定について
nrinetcom
PRO
2
110
ブラックボックス観測に基づくAI支援のプロトコルのリバースエンジニアリングと再現~AIを用いたリバースエンジニアリング~ @ SECCON 14 電脳会議 / Reverse Engineering and Reproduction of an AI-Assisted Protocol Based on Black-Box Observation @ SECCON 14 DENNO-KAIGI
chibiegg
0
130
Webアクセシビリティ技術と実装の実際
tomokusaba
0
190
Lookerの最新バージョンv26.2がやばい話
waiwai2111
1
150
AWS Bedrock Guardrails / 機密情報の入力・出力をブロックする — Blocking Sensitive Information Input/Output
kazuhitonakayama
2
190
チームメンバー迷わないIaC設計
hayama17
5
3.5k
問い合わせ自動化の技術的挑戦
recruitengineers
PRO
2
110
Introduction to Bill One Development Engineer
sansan33
PRO
0
380
Devinを導入したら予想外の人たちに好評だった
tomuro
0
800
社内でAWS BuilderCards体験会を立ち上げ、得られた気づき / 20260225 Masaki Okuda
shift_evolve
PRO
1
150
Featured
See All Featured
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
270
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
200
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.1k
Thoughts on Productivity
jonyablonski
75
5.1k
My Coaching Mixtape
mlcsv
0
63
Writing Fast Ruby
sferik
630
62k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
340
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
130
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
The Curious Case for Waylosing
cassininazir
0
260
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.2k
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)
Α͍͓Λ