Loading...
question swiftui swift October 30, 2023 How to convert Color type to hex and vice-versa while retaining alpha information?

The below should work both on macOS and iOS with one minor change. That is, use UIColor instead of NSColor if you’re planning to use it for iOS.

question swift macOS October 29, 2023 How to make Color conform to RawRepresentable in SwiftUI in macOS?

For various reasons you may want to convert the Color type to a String. And, below is a relatively cleaner way to do it.

question swift October 22, 2023 How to not break automatically in switch statements in Swift?

In Swift, the switch statement doesn’t automatically fall through to the next case. Each case block is designed to execute only the code within that case, and it doesn’t continue to the next case unless you use the fallthrough keyword.

question xcode sf symbol October 15, 2023 SF Symbol for the new X Social Network (previously Twitter)

I was looking for the SF Symbol for the latest Twitter icon, yes the X icon, but I couldn’t find any online. So, I created one here: https://github.com/rampatra/assets/blob/main/SFSymbols/X%20Social%20Network.svg. This works with the latest SF Symbol 5 so you can either import it to your SF Symbols app or use it directly in your Xcode by creating a new Symbol Image Set like shown below.

question swiftui macos October 15, 2023 How to display the app version and build number in a macOS/iOS SwiftUI app?

To display both the app version and build number in a SwiftUI macOS/iOS app, you can use the Bundle class to access information from the app’s Info.plist file. The Info.plist file contains various details about your application, including its version and build number. Here’s how you can do it:

question swift xcode October 8, 2023 How to get rid of 'Result of call to function is unused' warning in Swift/Xcode?

In Swift, if you encounter a “Result of call to ‘function’ is unused” warning, it means that you’re calling a function that returns a value (typically a result type, such as Result or any other type), but you’re not doing anything with the result. To get rid of this warning, you have a few options depending on the specific situation: