StaticActionBinding

public struct StaticActionBinding<FeatureType, ActionType> : CustomDebugStringConvertible where FeatureType : FeatureDefinition, ActionType : Action

Represents the binding of an action to a specific unconditional Feature.

These are use as the main entry point for performing actions, having been bound using the action function of Feature (provided by a protocol extension).

class DocumentManagementFeature: Feature {
    static let description = "Create documents"

    // This is where the binding is created
    static let createNew = action(DocumentCreateAction.self)

    static func prepare(actions: FeatureActionsBuilder) {
        actions.declare(createNew)
    }
}

... later you can perform the action directly ...

DocumentManagementFeature.createNew.perform( ... )

Note that you do not create these bindings explicitly, you must use the Flint `action` function for this.
  • The TopicPath to use when outputting logging for this action

    Declaration

    Swift

    public var logTopicPath: TopicPath { get }
  • Declaration

    Swift

    public var debugDescription: String { get }
  • A convenience function to perform the action in the main ActionSession.

    This function performs the action assuming the user initiated the action, and the application was the source of the request.

    The completion handler is called on main queue because the action is performed in the main ActionSession

    • param presenter: The object presenting the outcome of the action
    • param input: The value to pass as the input of the action
    • param completion: The completion handler to call.

    Declaration

    Swift

    public func perform(withInput input: ActionType.InputType,
                        presenter: ActionType.PresenterType,
                        completion: ((ActionOutcome) -> ())? = nil)
  • A convenience function to perform the action in the main ActionSession

    The completion handler is called on main queue because the action is performed in the main ActionSession

    • param presenter: The object presenting the outcome of the action
    • param input: The value to pass as the input of the action
    • param userInitiated: Set to true if the user explicitly chose to perform this action, false if not
    • param source: Indicates where the request came from
    • param completion: The completion handler to call.

    Declaration

    Swift

    public func perform(withInput input: ActionType.InputType,
                        presenter: ActionType.PresenterType,
                        userInitiated: Bool,
                        source: ActionSource,
                        completion: ((ActionOutcome) -> ())? = nil)
  • Convenience function for creating an activity for this action with a given input.

    This function can throw if the prepareActivity function on the action cannot return an activity for the give input.

  • param url: If specified, will be assumed to be a URL from a URLMapped feature that maps to invoke the action, for continuity
  • return: The activity that represents this action with the given input, or nil if there is no valid activity to represent it.

  • Note

    You do not need to use this normally if you use ActivityActionDispatchObserver which will publish activities automatically.

    Declaration

    Swift

    public func activity(withInput input: ActionType.InputType, withURL url: URL?) throws -> NSUserActivity?
  • Call to invoke the system Add Voice Shortcut view controller for the given input to the conditionally-available action represented by this action request. The action must support creating an NSUserActivity using Flint’s Activities conventions.

    This will create a shortcut that invokes the activity created for the Action‘s. If the Action does not support Activities, this will fail.

    This call will throw if the input fails to be converted to an intent or activity.

    • param input: The input to pass to the action when it is later invoked from the Siri Shortcut by the user.
    • param presenter: The UIViewController to use to present the view controller
    • param completion: The closure to call with the result of the operation

    Declaration

    Swift

    @available(iOS 12, *)
    public func addVoiceShortcut(withInput input: ActionType.InputType,
                                 presenter: UIViewController,
                                 completion: ((_ result: AddVoiceShortcutResult) -> Void)? = nil) throws
  • Perform an intent intended for this action. The action will be passed the input extracted from the intent, and a presenter that automatically calls the completion handler passed as an argument.

    This call will throw if the intent fails to be converted to an input for the action.

    • param intent: The intent received from an Intent Extension handler. This must be of the same type as this actions’s IntentType
    • param completion: The intent handler completion closure from an Intent Extension handler.
    • return: The result of performing the action.

    Declaration

    Swift

    func perform(withIntent intent: ActionType.IntentType, completion: @escaping (ActionType.IntentResponseType) -> Void) throws -> MappedActionResult
  • Perform an intent intended for this action. The action will be passed the input extracted from the intent, and the presenter (which must be an IntentResponsePresenter) passed in here is passed to the action.

    This call will throw if the intent fails to be converted to an input for the action.

    • param intent: The intent received from an Intent Extension handler. This must be of the same type as this actions’s IntentType
    • param completion: The intent handler completion closure from an Intent Extension handler.
    • return: The result of performing the action.

    Declaration

    Swift

    func perform(withIntent intent: ActionType.IntentType, presenter: ActionType.PresenterType) throws -> MappedActionResult
  • Call to invoke the system Add Voice Shortcut view controller for the given input to the conditionally-available action represented by this action request. The action must support creating an INIntent for a custom intent extension to be invoked.

    This will create a shortcut that invokes the INIntent returned by the Action‘s intent(withInput:) function. If that function returns nil (or is not defined by your Action), it will attempt to create an NSUserActivity for the Action and instead use that. If the Action does not support Activities, this will fail.

    This call will throw if the input fails to be converted to an intent or activity.

  • param input: The input to pass to the action when it is later invoked from the Siri Shortcut by the user.
  • param presenter: The UIViewController to use to present the view controller
  • param completion: A closure called with the outcome.

  • Note

    This variant exists for the specialisation that will call intent(for:) on the Action to create an an intent for the shortcut.

    Declaration

    Swift

    @available(iOS 12, *)
    func addVoiceShortcut(withInput input: ActionType.InputType,
                                 presenter: UIViewController,
                                 completion: ((_ result: AddVoiceShortcutResult) -> Void)? = nil) throws
  • Show the system’s Voice Shortcut editing UI for the given shortcut. You obtain instances of these shortcuts from INVoiceShortcutCenter which has APIs to return the shortcuts that currently exist.

    This call will throw if the input fails to be converted to an intent or activity.

  • param shortcut: The voice shortcut received from INVoiceShortcutCenter
  • param presenter: A view controller from which the editing UI will be presented
  • param completion: A closure called with the outcome of the editing.

  • Declaration

    Swift

    @available(iOS 12, *)
    func editVoiceShortcut(_ shortcut: INVoiceShortcut,
                                  presenter: UIViewController,
                                  completion: ((_ result: EditVoiceShortcutResult) -> Void)? = nil)
  • Create an INShortcut instance for the given input. Use when pre-registering shortcuts with INVoiceShortcuteCenter

    This call will throw if the input fails to be converted to an intent or activity.

    • param input: The input to the action, for which you wish to create a shortcut

    • return: The shortcut, or nil if the action’s intent(withInput:) function vetoed creation of the intent by returning nil.

    Declaration

    Swift

    @available(iOS 12, *)
    func shortcut(withInput input: ActionType.InputType) throws -> INShortcut?
  • Donate an intent-based shortcut to this Action to Siri for the given input.

    This call will throw if the input fails to be converted to an intent or activity.

    • param input: The input to the action, for which you wish to donate a shortcut

    Declaration

    Swift

    @available(iOS 12, *)
    func donateToSiri(withInput input: ActionType.InputType) throws