Skip to content

Instantly share code, notes, and snippets.

@noppefoxwolf
Created June 3, 2022 17:25
Show Gist options
  • Save noppefoxwolf/80e779a004957e65f39ebb089b2d9f96 to your computer and use it in GitHub Desktop.
Save noppefoxwolf/80e779a004957e65f39ebb089b2d9f96 to your computer and use it in GitHub Desktop.
import Foundation
import SFSafeSymbols
import UIKit
@resultBuilder
public struct MenuBuilder {
public static func buildBlock(_ components: UIMenuElement...) -> [UIMenuElement] {
components
}
}
extension UIMenu {
public convenience init(
title: String = "", image: UIImage? = nil, identifier: Identifier? = nil,
options: Options = .init(), @MenuBuilder children: () -> [UIMenuElement]
) {
self.init(
title: title, image: image, identifier: identifier, options: options,
children: children())
}
public convenience init(
title: String = "", systemSymbol: SFSymbol, identifier: Identifier? = nil,
options: Options = .init(), @MenuBuilder children: () -> [UIMenuElement]
) {
self.init(
title: title, image: UIImage(systemSymbol: systemSymbol), identifier: identifier,
options: options,
children: children())
}
}
extension UIAction {
public convenience init(
title: String = "", subtitle: String? = nil, systemSymbol: SFSymbol,
identifier: Identifier? = nil, discoverabilityTitle: String? = nil,
attributes: UIMenuElement.Attributes = .init(), state: UIMenuElement.State = .off,
handler: @escaping UIActionHandler
) {
self.init(
title: title, subtitle: subtitle, image: UIImage(systemSymbol: systemSymbol),
identifier: identifier, discoverabilityTitle: discoverabilityTitle,
attributes: attributes, state: state, handler: handler)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment