Skip to content

Instantly share code, notes, and snippets.

@Heilum
Last active November 1, 2019 02:50
Show Gist options
  • Save Heilum/c84a9cea868cfa774cddf4a3423cf64a to your computer and use it in GitHub Desktop.
Save Heilum/c84a9cea868cfa774cddf4a3423cf64a to your computer and use it in GitHub Desktop.
Setting associated userObject to UIView
//
// UIView+SF.swift
// WechatTail
//
// Created by CHENWANFEI on 2019/9/22.
// Copyright © 2019 SwordFish. All rights reserved.
//
import UIKit
var g_UIView_AssociatedObjectHandle: UInt8 = 0
extension UIView{
var userObject:Any? {
get {
return objc_getAssociatedObject(self, &g_UIView_AssociatedObjectHandle)
}
set {
objc_setAssociatedObject(self, &g_UIView_AssociatedObjectHandle, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment