Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
EnumのRawValueで好きな型を使いたい
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
hmhm
April 14, 2018
86
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
EnumのRawValueで好きな型を使いたい
hmhm
April 14, 2018
More Decks by hmhm
See All by hmhm
Advanced Codable
hmhmsh
0
31
Featured
See All Featured
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
360
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
710
Bash Introduction
62gerente
615
220k
Scaling GitHub
holman
464
140k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Deep Space Network (abreviated)
tonyrice
0
370
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.7k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
570
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
360
Practical Orchestrator
shlominoach
192
12k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Transcript
EnumͷRawValueͰ͖ͳܕ Λ͍͍ͨ
ࣗݾհ ▸ ୩ɹॠ࠸ ▸ Twitterɿ@shunkun_san ▸ GitHubɿ@hmhmsh ▸ ݴޠɿSwiftɾObjective-CɾJava ▸
࠷ۙͷग़དྷࣄɿՖคͱ໌
ςΩετ ͖͔͚ͬ ▸ ʮSwiftͷྻڍܕ͕ڧ͍ʯͱ͍͏ͷ͕ʹ্͕͍ͬͯΔ ʢΒ͍͠ʁʣ ▸ ྻڍܕͷԿ͕ڧ͍͔ ▸ Raw Valueͱ͍͏ػೳͳͷ͔
▸ Associated Valueͱ͍͏ػೳͳͷ͔
Enum Enumʢྻڍܕʣ enum CompassPoint { case north case south case
east case west } let south = CompassPoint.south
Raw Value
Enum > Raw Value Raw Value ‣ έʔεʹରԠͨ͠Λ࣋ͨͤΒΕΔ ‣ ͷܕશͯಉ͡
‣ ͷܕ ‣ จࣈྻϦςϥϧɿCharacterܕɾStringܕ ‣ ϦςϥϧɿIntܕɾDoubleܕ
Raw Value enum CompassPoint: String { case north case south
case east case west } let south = CompassPoint.south.rawValue // "south" Enum > Raw Value
Raw Value ▸ Raw ValueʹࢦఆͰ͖Δܕܾ·͍ͬͯͨ ‣ จࣈྻϦςϥϧɿCharacterܕɾStringܕ ‣ ϦςϥϧɿIntܕɾDoubleܕ ‣
Raw Valueͷܕͱ͖ͯ͠ͳܕΛ༻͍ͨ͠ Enum > Raw Value
EnumΛRawRepresentableʹ ४ڌͤͯ͞Έͨ
RawRepresentable public protocol RawRepresentable { associatedtype RawValue public init?(rawValue: Self.RawValue)
public var rawValue: Self.RawValue { get } } Enum > Raw Value
RawRepresentable ▸ associatedtype RawValueʹ੍͕ͳ͍ ▸ ੍ɿprotocol४ڌͳͲ ▸ ͖ͳܕΛRawValueʹೖΕΔ ▸ ࣗ࡞structΛRaw
Valueͱͯͬͯ͠ΈΑ͏ Enum > Raw Value
Custom Raw Value // ༏ struct RadioActor { let name:
String } Enum > Raw Value
Custom Raw Value struct RadioActor { let name: String }
enum Popteamepic { case Popuko case Pipimi } Enum > Raw Value
Custom Raw Value struct RadioActor { let name: String }
enum Popteamepic { case Popuko case Pipimi } extension Popteamepic: RawRepresentable { typealias RawValue = RadioActor Enum > Raw Value
Custom Raw Value struct RadioActor { let name: String }
enum Popteamepic { case Popuko case Pipimi } extension Popteamepic: RawRepresentable { typealias RawValue = RadioActor var rawValue: RadioActor { switch self { case .Popuko: return RadioActor(name: "ߐݪਖ਼࢜") case .Pipimi: return RadioActor(name: "େ௩๕") } } Enum > Raw Value
Custom Raw Value struct RadioActor { let name: String }
enum Popteamepic { case Popuko case Pipimi } extension Popteamepic: RawRepresentable { typealias RawValue = RadioActor var rawValue: RadioActor { switch self { case .Popuko: return RadioActor(name: "ߐݪਖ਼࢜") case .Pipimi: return RadioActor(name: "େ௩๕") } } init?(rawValue: RadioActor) { switch rawValue.name { case "ߐݪਖ਼࢜": self = .Popuko case "େ௩๕": self = .Pipimi default: return nil } } } Enum > Raw Value
Custom Raw Value let popuko = Popteamepic.Popuko.rawValue // RadioActor let
name = popuko.name // "ߐݪਖ਼࢜" let radioActor = RadioActor(name: "େ௩๕") let pipimi = Popteamepic(rawValue: radioActor) // Popteamepic.Pipimi Enum > Raw Value
Ͱ͖ͨ
ςΩετ ·ͱΊ ▸ Enum > Raw Value ▸ จࣈྻɾࣈϦςϥϧ͕༻Մೳ ▸
EnumΛRawRepresentableʹ४ڌͤ͞Δ ▸ ࣗ࡞Ϋϥεɾߏମ༻͢Δ͜ͱ͕Ͱ͖Δ
Custom Raw Value ͍Ͳ͜Ζ͕Θ͔Βͳ͍
Thank you for listening