-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace animation name with Enums #22
Comments
Yes, instead of using Strings like enum Animation: String {
case FadeIn = "FadeIn"
} And since all properties are |
I would like to propose an alternative is to use typealise and constant, to keep the animation in String type value, but clear enough for the public interface know it's not any random string |
In my opinion if String type is not necessary an enum should be used in this case. Instead of search the animation name/constant I could make Animation. and see all the possibility and in Interface Builder there would be a select box instead of a textfield. @jamztang explain why you prefer String. |
I do prefer enum. Main reason we have to keep it as string type is because IBInpectables does not support drop down for Enums. Unless it already does? |
My mistake. It works only with UIColor. The only way is with workaround like : enum Animation: String {
case FadeIn = "FadeIn"
}
@IBDesignable
class SpringView: UIView {
var animation : Animation = .FadeIn{
didSet {
self.animationName = animation.rawValue
}
}
@IBInspectable var animationName: String = ""
|
@jamztang Using Enums or String Arrays is not possible for IBInspectables. I would prefer an Enumeration, like I wrote before. In InterfaceBuilder you have to use the String, and in code you can also use the String or the Enumeration: springView.animation = SpringView.Animation.FadeIn.rawValue |
@schneiderandre Enum doesn't appear in InterfaceBuilder. |
@PGLongo right, that's what I wrote, but as I mentioned we can use: @IBInspectable var animation: String and set it springView.animation = SpringView.Animation.FadeIn.rawValue |
Ok so this is to my surprise that it's not working for @IBInspectables :( typealias AnimationName = String
class SpringView : UIView {
@IBInspectable var animation : AnimationName = ""
} I'm actually looking into something like this: public struct SpringAnimation {
static let FadeIn = "fadeIn"
static let FadeOut = "fadeOut"
static let SlideLeft = "slideLeft"
}
// So to set it will be slightly nicer
springView.animation = SpringAnimation.FadeIn I do have one for Objective-C but I guess it's way too much addition to the code base, so I'll just link it here for our reference. Double property from @PGLongo is a clever workaround but if we change the I'm okay to go with either @schneiderandre solution or the |
Swift 1.2 supports @objc enums. |
@SachiraChin also objc enums doesn't appear in InterfaceBuilder. |
Right. I guess right note the best is to just keep our options open, optimistically I think we might see Apple support enums in the future |
I think it should be better use enum for animation name, curve and properties. If you agree, I could take care about it.
The text was updated successfully, but these errors were encountered: