This is a sample code of how to write enum and enum.
Here, we created a class called “person” and registered Kabigon's name and hometown using enum.
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
import UIKit | |
enum Country { | |
case japan | |
case america | |
case kanada | |
case china | |
} | |
class person: NSObject { | |
var name:String! | |
var from:Country! | |
} | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let kabigon = person() | |
kabigon.name = "カビゴン" | |
kabigon.from = Country.america | |
switch kabigon.from { | |
case .japan: | |
print(kabigon.name + "は日本から来ました。") | |
case .america: | |
print(kabigon.name + "はアメリカから来ました。") | |
case .kanada: | |
print(kabigon.name + "はカナダから来ました。") | |
case .china: | |
print(kabigon.name + "は中国から来ました。") | |
default: | |
print("error") | |
} | |
} | |
} |