NSObjectProtocol
protocol NSObjectProtocol
-
Mechanica
Returns the type of an object conforming to
NSObjectProtocolasString.Declaration
Swift
public var type: String { get } -
Mechanica
Returns the type of an object instance conforming to
NSObjectProtocolasString.Declaration
Swift
public static var type: String { get }
-
Mechanica
Sets an associated value using a given key and association policy.
Declaration
Swift
public func setAssociatedValue<T>(_ value: @autoclosure () -> T?, forKey key: UnsafeRawPointer, andPolicy policy: objc_AssociationPolicy = .OBJC_ASSOCIATION_RETAIN_NONATOMIC)Parameters
valueThe value to associate with the key key for object. Pass nil to clear an existing association.
keyThe key for the association.
policyThe policy for the association.
-
Mechanica
Returns the value associated for a given key.
Declaration
Swift
public func getAssociatedValue<T>(forKey key: UnsafeRawPointer) -> T?Parameters
keyThe key for the association.
Return Value
The value associated with the key for object.
-
Mechanica
Removes an associated value using a given key and association policy.
Declaration
Swift
public func removeAssociatedValue(forKey key: UnsafeRawPointer, andPolicy policy: objc_AssociationPolicy = .OBJC_ASSOCIATION_RETAIN_NONATOMIC)Parameters
keyThe key for the association.
policyThe policy for the association.
-
Mechanica
Removes all the associated values.
Declaration
Swift
public func removeAllAssociatedValues()
-
Mechanica
Couple of
Selectorwhere the method corresponding to the first one needs to be exchanged with the second one.Declaration
Swift
public typealias SwizzlingSelectors = (originalSelector: Selector, swizzledSelector: Selector) -
Mechanica
Exchanges the implementations of two methods given their corresponding selectors.
To use method swizzling with your Swift classes there are two requirements that you must comply with:
- The class containing the methods to be swizzled must extend NSObject.
- The methods you want to swizzle must have the dynamic attribute.
Note
In Objective-C you’d perform the swizzling in load() , but this method is not permitted in Swift. But load is a Objective-C only method and cannot be overridden in Swift, trying to do it anyway will result in a compile time error. The next best place to perform the swizzling is in initialize, a method called right before the first method of your class is invoked.
Declaration
Swift
public static func swizzle(method originalSelector: Selector, with swizzledSelector: Selector)Parameters
originalSelectorSelectorfor the original methodswizzledSelectorSelectorfor the swizzled methos -
Declaration
Swift
public static func swizzle(_ selectors: [SwizzlingSelectors])
NSObjectProtocol Extension Reference