Skip to content

A collection of macros to make SwiftUI development easier.

License

Notifications You must be signed in to change notification settings

latencyzero/LZSwiftUIMacros

Repository files navigation

LZ SwiftUI Macros

A collection of Swift macros for working with SwiftUI.

Sadly, the only one here doesn’t work, because Swift macros are not powerful enough.

FocusedCommand

To ease the burden of implementing focused commands, as described in this article, I had hoped these macros would help:

#FocusedCommand("Duplicate")

would expand to

struct DuplicateCommandKey : FocusedValueKey {
    typealias Value = (Bool, () -> Void)
}
extension FocusedValues {
    var duplicateCommand : DuplicateCommandKey.Value? {
        get {
            self [DuplicateCommandKey.self]
        }
        set {
            self [DuplicateCommandKey.self] = newValue
        }
    }
}
extension View {
    func onDuplicate(disabled: Bool = false, perform: @escaping () -> ()) -> some View {
        self.focusedSceneValue(\.duplicateCommand, (disabled, perform))
    }
}

But alas, it is not allowed to introduce extensions. So I guess we’re all stuck with tons of annoying boilerplate.

About

A collection of macros to make SwiftUI development easier.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages