Category Archives: Swift

Swift issues and solutions

Funny one – but it doesn’t crash

Would you expect this SwiftUI code to crash or otherwise fail to run? struct ContentView: View { var body: some View { NavigationView { NavigationLink(destination: ContentView()) { Text(“Show another”) }.navigationBarTitle(“Recursive navigation”) } } } Nope, body property for the new … Continue reading

Posted in SwiftUI | Tagged , | Leave a comment

Small SwiftUI annoyances

Some (maybe minor) things that I’ve observed while learning SwiftUI and doing some hands on testing: When you present a set of unrelated items in a Picker (i.e. without ForEach) or a set of random tab items in a TabView (in … Continue reading

Posted in SwiftUI | Tagged | Leave a comment

Don’t set NSPopupButton’s menu.items!

Since macOS 10.14 (Mojave) you can set the items of the internal NSMenu of a NSPopupButton in a Cocoa app using simple code like this: menu.items = […] But if your app also targets macOS 10.13 (High Sierra), don’t do … Continue reading

Posted in macOS | Tagged , , , , , , , , , | Leave a comment

2D virtualization

Do you need to develop a UI grid component displaying column-aligned cells for rows bound to specific items that the client would provide? Do yourself a favor and prepare for performance improvements when you design it. I mean: don’t just … Continue reading

Posted in Architecture, Development, Swift | Tagged , , | Leave a comment

Daylight may ruin your date

(No, this post doesn’t include dating advice. For such content, your best shot is probably YouTube. :-)) This is instead about Date values in Swift*. Which sometimes you might need to update by “components”. Such as by adding a specific number … Continue reading

Posted in Swift | Tagged , , , , , | Leave a comment

Swift optionals can save the day

Although generics in Swift are somehow limited at this time, there is a nice variance-related feature available when using optionals: you can assign a non-optional to an optional variable, an array of non-optionals to an array of optionals (these two are classics), … Continue reading

Posted in Swift | Tagged , , , | Leave a comment

Enum cases with associated values are powerful but we need follow-up patterns

Let’s assume we want to use Swift to develop a function to round floating point numbers, in different ways according to a context. For example, sometimes the result of such rounding could be the input value itself (like on a … Continue reading

Posted in Swift | Tagged , , , , , , | Leave a comment