Created
February 21, 2018 10:01
-
-
Save mspvirajpatel/8ec4f97753417d5b2c33e7d4d2b61d55 to your computer and use it in GitHub Desktop.
How to create an IBInspectable of type enum
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
enum StatusShape:Int { | |
case Rectangle | |
case Triangle | |
case Circle | |
} | |
// Programmatically: use the enum | |
var shape:StatusShape = .Rectangle | |
// IB: use the adapter | |
@IBInspectable var shapeAdapter:Int { | |
get { | |
return self.shape.rawValue | |
} | |
set( shapeIndex) { | |
self.shape = StatusShape(rawValue: shapeIndex) ?? .Rectangle | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment