Skip to content

Instantly share code, notes, and snippets.

@alexito4
Last active August 12, 2019 06:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexito4/ec05e16dc201c6befebd to your computer and use it in GitHub Desktop.
Save alexito4/ec05e16dc201c6befebd to your computer and use it in GitHub Desktop.
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