Comments (12)
Yes, instead of using Strings like "fadeIn"
we could use an enum like this
enum Animation: String {
case FadeIn = "FadeIn"
}
And since all properties are @IBInspectable
we have to use rawValue
.
This gives us the type safety of an Enum in Code and we are still able to set the properties in Interface Builder.
from spring.
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
from spring.
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.
from spring.
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?
from spring.
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 = ""
from spring.
@jamztang Using Enums or String Arrays is not possible for IBInspectables.
I would also try to avoid two variables for setting the same property. This leads to confusion.
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
from spring.
@schneiderandre Enum doesn't appear in InterfaceBuilder.
from spring.
@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
from spring.
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 animation
to animationName
will cause incompatibility issues for v1.0.0 which is already out there.
I'm okay to go with either @schneiderandre solution or the struct
solution.
from spring.
Swift 1.2 supports @objc enums.
https://developer.apple.com/swift/blog/?id=22
from spring.
@SachiraChin also objc enums doesn't appear in InterfaceBuilder.
from spring.
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
from spring.
Related Issues (20)
- LOST all ui from Storyboard
- KeyboardLayoutConstraint + UIAlertController animation are broken [iOS 11] HOT 1
- Reverse animations?
- Mixed animations not working? HOT 2
- Documentation
- Swift 4.2 HOT 7
- .podspec Add s.swift_version = "4.2" , Please HOT 3
- Cant build for swift 4.2 HOT 6
- 'VoxeetSDK' is unavailable: cannot find Swift declaration for this class HOT 1
- Seems not to work with iPhone X models HOT 2
- Doesn't working at swift 5 HOT 14
- DesignableButton as open class HOT 1
- KeyboardLayoutConstraint: Space above keyboard?
- Feature Request - Swift Package Manager Support HOT 2
- The example is not working HOT 1
- Depricated
- Animation
- What time to update for Swift 5.0
- Cubic Animation
- very g
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring.