Last active
August 12, 2019 06:32
-
-
Save alexito4/ec05e16dc201c6befebd to your computer and use it in GitHub Desktop.
Swift enums and UISegmentedControl
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 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