NSObject
extension NSObject
-
Strong referenced associated object
Declaration
Swift
public var associatedObject: Any? { get set }
-
set an associated object for key pointer Example usage: private struct SomeKey { static var Key =
RandomKey
}setAssociatedObejct(someObject, forKeyPointer: &SomeKey.Key)
Declaration
Swift
@discardableResult public func setAssociatedObejct(_ object: Any, forKeyPointer pointer: UnsafeRawPointer? = nil, associationPolicy: objc_AssociationPolicy = .OBJC_ASSOCIATION_RETAIN_NONATOMIC) -> Any?
Parameters
object
an object to be associated
pointer
pointer
associationPolicy
associationPolicy, default to .OBJC_ASSOCIATION_RETAIN_NONATOMIC (strong reference). Use .OBJC_ASSOCIATION_ASSIGN for weak reference.
Return Value
old associated object if existed
-
Undocumented
Declaration
Swift
public func getAssociatedObject(forKeyPointer pointer: UnsafeRawPointer? = nil) -> Any?
-
Undocumented
Declaration
Swift
@discardableResult public func clearAssociatedObject(forKeyPointer pointer: UnsafeRawPointer? = nil) -> Any?
-
Observe property with keyPath. Note:
dynamic
attribute is necessary for Swift classesDeclaration
Swift
public func observe(_ keyPath: String, withHandler handler: @escaping Observer.ObserverHandler)
Parameters
keyPath
keyPath for the property
handler
Observer handler
-
Remove the observation for keyPath
Declaration
Swift
public func removeObservation(forKeyPath keyPath: String)
Parameters
keyPath
keyPath of the observation