Dušan Tadić https://www.dusantadic.dev/ Recent content on Dušan Tadić Hugo -- gohugo.io en-us Sat, 18 May 2019 15:02:19 +0000 How not to use enums in Swift https://www.dusantadic.dev/post/how-not-to-use-enums/ Sat, 18 May 2019 15:02:19 +0000 https://www.dusantadic.dev/post/how-not-to-use-enums/ In Swift, enums are powerful. So powerful in fact, that it’s easy to abuse them. Here are some examples of enum abuse, and alternative approaches. App themes When adding dark theme to your app, instead of a boolean flag, you may add enum like this: enum Theme { case dark case light } Sure, using an enum here seems like an obvious choice. But features expand, and you may want to add multiple themes. Make UIControl More Swifty https://www.dusantadic.dev/post/make-uicontrol-more-swifty/ Sat, 09 Mar 2019 22:11:43 +0100 https://www.dusantadic.dev/post/make-uicontrol-more-swifty/ In Objective-C, it is possible to set a property either by using dot notation (eg. foo.prop = bar) or by calling a setter (eg. [foo setProp: bar]). In Swift, there’s only one way - the dot notation. If you needed custom behavior in Objective-C for getters or setters, you’d implement a setter and/or getter method. In Swift, you’d use computed properties like this: var foo: Bar { get { [...] } set { [.