"Swift-Summary" enumeration

Source: Internet
Author: User

Declaring enumerations
enum Direction {    case North    case East    case West    case South}

You can also use a case

enum Direct {    case North, East, South}
Using enumerations
var dirct = Direction.East.West
Related values

You can use an enumeration to store any related reference

enum PersonInfo {    case Age(Int)    case Name(String)}
var person = PersonInfo.Name("ttf")switch person {case .Age(let age)://获得这个值    print("person‘s age is \(age)")case .Name(let name):    print("person‘name is \(name)")}
Enumeration with initial values
/**以字符为初始值的枚举*/enum DirWithChar: Character {    case"\t"    case"\n"    case"\0"    case"\r"}
/**以Int为初始值的枚举*/enum DirWithInt: Int {    case0    case West    case East    case South}

Get the initial value

let dirValue = DirWithInt.East.rawValue

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Swift-Summary" enumeration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.