NSObject

extension NSObject
  • Casts the receiver to the given interface type.

    For more information, see the documentation for the Dynamic struct.

    Declaration

    Swift

    public func `as`<I>(interface: I.Type) -> I

    Parameters

    interface

    The interface to which the receiver should be converted.

    Return Value

    The receiver as if it conformed to the given interface.

  • Returns the class referred to by the receiver as if it conformed to the given interface.

    Methods on the interface should be declared as instance methods.

    For more information, see the documentation for the Dynamic struct.

    Declaration

    Swift

    public static func `as`<I>(interface: I.Type, protocol: Protocol? = nil) -> I

    Parameters

    interface

    The interface to which the class should be cast.

    protocol

    If the interface is a private protocol or is otherwise invisible to Objective-C via NSClassFromString, you may need to pass the protocol a second time as this parameter. For example, MyClass.as(interface: MyInterface.self, protocol: MyInterface.self).

    Return Value

    The class, “cast” to the interface.

  • Allocates an object corresponding to the callee’s class and casts it to the type of the passed interface.

    Declaration

    Swift

    public static func alloc<I>(interface: I.Type) -> I

    Parameters

    interface

    The interface which the allocated type should be cast to. You usually want this to have an initializer method which should be chained to this call.

    Return Value

    The allocated instance of the class, as the interface type.