SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public final class ObjectAssociation<T: AnyObject> {
  2.    
  3.     private let policy: objc_AssociationPolicy
  4.    
  5.     /// - Parameter policy: An association policy that will be used when linking objects.
  6.     public init(policy: objc_AssociationPolicy = .OBJC_ASSOCIATION_RETAIN_NONATOMIC) {
  7.        
  8.         self.policy = policy
  9.     }
  10.    
  11.     /// Accesses associated object.
  12.     /// - Parameter index: An object whose associated object is to be accessed.
  13.     public subscript(index: AnyObject) -> T? {
  14.        
  15.         get { return objc_getAssociatedObject(index, Unmanaged.passUnretained(self).toOpaque()) as! T? }
  16.         set { objc_setAssociatedObject(index, Unmanaged.passUnretained(self).toOpaque(), newValue, policy) }
  17.     }
  18. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top