Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum ProfileSection: Int {
- case Time, WarmUp, CoolDown, Count
- static var count = {
- return ProfileSection.Count.rawValue
- }
- static let sectionTitles = [
- Time: "Time",
- WarmUp: "Warm Up",
- CoolDown: "Cool Down"
- ]
- func sectionTitle() -> String {
- if let sectionTitle = ProfileSection.sectionTitles[self] {
- return sectionTitle
- } else {
- return ""
- }
- }
- }
- return ProfileSection.count()
- guard let section = ProfileSection(rawValue: section) else { return "" }
- return section.sectionTitle()
- guard let section = ProfileSection(rawValue: section) else { return 1 }
- //method 2 :
- enum Device {
- case phone(name: String, screenSize: CGSize)
- case watch(name: String, screenSize: CGSize)
- case tablet(name: String, screenSize: CGSize)
- static func fromDefaults(rawValue: String, name: String, screenSize: CGSize) -> Device? {
- switch rawValue {
- case "phone": return Device.phone(name: name, screenSize: screenSize)
- case "watch": return Device.watch(name: name, screenSize: screenSize)
- case "tablet": return Device.tablet(name: name, screenSize: screenSize)
- default: return nil
- }
- }
- }
- let b = Device.fromDefaults("phone", name: "iPhone SE", screenSize: CGSize(width: 640, height: 1136))
- print(b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement