Functions

The following functions are available globally.

  • Mechanica

    Sets an associated value for a given object using a given key and association policy.

    Declaration

    Swift

    public func setAssociatedValue<T>(_ value: T?, forObject object: Any, usingKey key: UnsafeRawPointer, andPolicy policy : objc_AssociationPolicy = .OBJC_ASSOCIATION_RETAIN_NONATOMIC)

    Parameters

    value

    The value to associate with the key key for object. Pass nil to clear an existing association.

    object

    The source object for the association.

    key

    The key for the association.

    policy

    The policy for the association.

  • Mechanica

    Returns the value associated with a given object for a given key.

    Declaration

    Swift

    public func getAssociatedValue<T>(forObject object: Any, usingKey key: UnsafeRawPointer) -> T?

    Parameters

    object

    The source object for the association.

    key

    The key for the association.

    Return Value

    he value associated with the key key for object.

  • Mechanica

    Clears an associated value for a given object using a given key and association policy.

    Declaration

    Swift

    public func clearAssociatedValue(forObject object: Any, usingKey key: UnsafeRawPointer, andPolicy policy : objc_AssociationPolicy = .OBJC_ASSOCIATION_RETAIN_NONATOMIC)

    Parameters

    object

    The source object for the association.

    key

    The key for the association.

    policy

    The policy for the association.

  • Mechanica

    Optional-string-coalescing operator.

    The ??? operator takes any optional on its left side and a default string value on the right, returning a string. If the optional value is non-nil, it unwraps it and returns its string description, otherwise it returns the default value.

    Credits

    See more

    Declaration

    Swift

    public func ??? <T>(optional: T?, defaultValue: @autoclosure () -> String) -> String