blog icon indicating copy to clipboard operation
blog copied to clipboard

🍁 What you don't know is what you haven't learned

Results 195 blog issues
Sort by recently updated
recently updated
newest added

Use a custom `KeyAwareView` that uses an `NSView` that checks for `keyDown` method. In case we can't handle certain keys, call `super.keyDown(with: event)` ```swift import SwiftUI import KeyboardShortcuts struct KeyAwareView:...

swift
macOS
swiftUI

If you use enum case as key in Dictionary, JSONEncoder will encode it as Array. For example ```swift enum Vehicle: String, Codable { case car case truck } struct Container:...

swift

With `ButtonStyle`, the `disabled` modifier does not seem to work, we need to use `allowsHitTesting`. ```swift import SwiftUI struct ActionButtonStyle: ButtonStyle { func makeBody(configuration: Configuration) -> some View { HStack...

swift
swiftUI

Supposed we have `Book` object ```swift struct Book: Identifiable, Codable, Hashable { @DocumentID var id: String? } ``` We should use [FieldPath](https://firebase.google.com/docs/reference/node/firebase.firestore.FieldPath) instead of `id` for query ```swift let booksRef:...

swift

```swift textField.delegate = self ``` ```swift NSTextFieldDelegate func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool { if (commandSelector == #selector(NSResponder.insertNewline(_:))) { // Do something against ENTER key...

swift
macOS

To avoid compiler error `Unprintable ASCII character found in source file`, from Swift 5, we can use `isASCII`. Run this from the generator app that generates Swift code. ```swift let...

iOS
swift

Use `DefaultValue` to provide `defaultValue` in our property wrapper `DefaultCodable` ```swift public protocol DefaultValue { associatedtype Value: Codable static var defaultValue: Value { get } } public enum DefaultBy {...

swift

## Using WindowGroup New in SwiftUI 2.0 for iOS 14 and macOS 11.0 is `WindwGroup` which is used in `App` protocol. WindowGroup is ideal for document based applications where you...

swift
macOS
swiftUI

## Run Timer in command line application ```swift Timer.scheduledTimer(withTimeInterval: seconds, repeats: false, block: { _ in completion(.success(())) }) RunLoop.current.run() ``` ## Read more - https://www.hackingwithswift.com/articles/117/the-ultimate-guide-to-timer - https://learnappmaking.com/timer-swift-how-to/

swift

Add a hidden overlay `UIContextMenuInteraction`. Provide preview in `previewProvider` and actions in `actionProvider`. Use `@ViewBuilder` to make declaring preview easy. ```swift extension View { func contextMenuWithPreview( actions: [UIAction], @ViewBuilder preview:...

iOS
swift
swiftUI