Listing: "It is impossible to build because it does not have initializers available"

I cannot initialize an enumeration using the rawValue initializer. Any thoughts? The error is commented below:

//: Playground - noun: a place where people can play // Xcode Version 7.3 (7D175) import UIKit enum Theme { case Default, Dark, Graphical } let possibleTheme = Theme(rawValue: 1) // Error: 'Theme' cannot be constructed because it has no accessible initializers. 
+5
source share
1 answer
 enum Theme: Int { case Default, Dark, Graphical } let possibleTheme = Theme(rawValue: 1) // Dark 

An enumeration has no initial value unless you specify its type. Possible types of raw values ​​are: String , Character and any of the number types. Documentation

+16
source

Source: https://habr.com/ru/post/1245649/


All Articles