This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var directionToHead: CompassPoint | |
directionToHead = .south | |
switch directionToHead { | |
case .north: | |
print("Lots of planets have a north") | |
case .south: | |
print("Watch out for penguins") | |
case .east: | |
print("Where the sun rises") | |
case .west: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let somePlanet = Planet.earth | |
switch somePlanet { | |
case .earth: | |
print("Mostly harmless") | |
default: | |
print("Not a safe place for humans") | |
} | |
// Prints "Mostly harmless" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Beverage: CaseIterable { | |
case coffee, tea, juice | |
} | |
let numberOfChoices = Beverage.allCases.count | |
print("\(numberOfChoices) beverages available") | |
// Prints "3 beverages available" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for beverage in Beverage.allCases { | |
print(beverage) | |
} | |
// coffee | |
// tea | |
// juice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum JsonType { | |
case int(Int) | |
case string(String) | |
case bool(Bool) | |
case object([String: JsonType]) | |
case array([JsonType]) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jsonInt: JsonType = JsonType.int(3) | |
jsonInt = JsonType.int(4) | |
var jsonString = JsonType.string("hi") | |
var jsonBool = JsonType.bool(false) | |
var jsonObject = JsonType.object(["예제": jsonBool]) | |
var jsonArray = JsonType.array([jsonInt, jsonString, jsonBool, jsonObject]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Barcode { | |
case upc(Int, Int, Int, Int) | |
case qrCode(String) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var productBarcode = Barcode.upc(8, 85909, 51226, 3) | |
productBarcode = .qrCode("ABCDEFGHIJKLMNOP") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum DevideCharacter: Character { | |
case squareBracketOpen = "[" | |
case squareBracketClose = "]" | |
case curlyBracketOpen = "{" | |
case curlyBracketClose = "}" | |
case colon = ":" | |
case whiteSpace = " " | |
case comma = "," | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if input.first == DevideCharacter.squareBracketOpen.rawValue { | |
print("첫 글자는 열리는 대괄호") | |
} |