Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumerations has no rawValue member now #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 8. Enumerations.playground/contents.xcplayground
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
<code source-file-name='section-1.swift'/>
</sections>
<timeline fileName='timeline.xctimeline'/>
</playground>
</playground>
10 changes: 5 additions & 5 deletions 8. Enumerations.playground/section-1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ enum StatusCode: Int
case YetAnotherResult // Unspecified values are auto-incremented from the previous value
}

// We can get the raw value of an enumeration value with the rawValue member:
StatusCode.OtherResult.rawValue
// We can get the raw value of an enumeration value with the toRaw() method:
StatusCode.OtherResult.toRaw()

// We can give enumerations many types. Here's one of type Character:
enum ASCIIControlCharacter: Character
Expand All @@ -143,18 +143,18 @@ enum FamilyPet: String
}

// And we can get their raw value as well:
FamilyPet.Ferret.rawValue
FamilyPet.Ferret.toRaw()

// We can also generate the enumeration value from the raw value. Note that this is an optional
// because not all raw values will have a matching enumeration:
var pet = FamilyPet(rawValue: "Ferret")
var pet = FamilyPet.fromRaw("Ferret")

// Let's verify this:
if pet != .None { "We have a pet!" }
else { "No pet :(" }

// An example of when a raw doesn't translate to an enum, leaving us with a nil optional:
pet = FamilyPet(rawValue: "Snake")
pet = FamilyPet.fromRaw("Snake")
if pet != .None { "We have a pet" }
else { "No pet :(" }

2 changes: 1 addition & 1 deletion 8. Enumerations.playground/timeline.xctimeline
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
version = "3.0">
<TimelineItems>
<LoggerValueHistoryTimelineItem
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=5526&amp;EndingColumnNumber=5&amp;EndingLineNumber=20&amp;StartingColumnNumber=4&amp;StartingLineNumber=20&amp;Timestamp=432600934.12383">
documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=5523&amp;EndingColumnNumber=5&amp;EndingLineNumber=20&amp;StartingColumnNumber=4&amp;StartingLineNumber=20&amp;Timestamp=435340083.485168">
</LoggerValueHistoryTimelineItem>
</TimelineItems>
</Timeline>