Skip to content

Instantly share code, notes, and snippets.

@alexito4 alexito4/enums.playground
Last active Aug 12, 2019

Embed
What would you like to do?
Swift enums and UISegmentedControl
import UIKit
enum Size: Int, CustomStringConvertible {
case S = 0
case M
case L
case XL
static func allValues() -> [String] {
return [S, M, L, XL].map({$0.description})
}
static func count() -> Int {
return allValues().count
}
public var description: String {
switch self {
case .S:
return "S"
case .M:
return "M"
case .L:
return "L"
case .XL:
return "XL"
}
}
}
Size.count()
Size.allValues()
let segmented = UISegmentedControl(items: Size.allValues())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.