Swift Tips: Failable init

by Pixpedia
if let myButton = MyButton(buttonType: .default) {
// init the button successfully
} else {
// could not init the button
}
enum ButtonTypes: Int {
case default
case primary
case secondary
case informative
}
let buttonType = ButtonTypes(rawValue: 2)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store