Skip to content

Instantly share code, notes, and snippets.

@kostapappas
Created December 15, 2018 08:56
Show Gist options
  • Save kostapappas/f8a8ef2bed298ef781af45dcdd68b900 to your computer and use it in GitHub Desktop.
Save kostapappas/f8a8ef2bed298ef781af45dcdd68b900 to your computer and use it in GitHub Desktop.
add row, sector, indexpath in button
extension UIButton {
private struct AssociatedKeys {
static var section = "section"
static var row = "row"
}
var section: Int {
get {
guard let number = objc_getAssociatedObject(self, &AssociatedKeys.section) as? Int else {
return -1
}
return number
}
set(value) {
objc_setAssociatedObject(self,
&AssociatedKeys.section,
Int(value),
objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
var row: Int {
get {
guard let number = objc_getAssociatedObject(self, &AssociatedKeys.row) as? Int else {
return -1
}
return number
}
set(value) {
objc_setAssociatedObject(self,
&AssociatedKeys.row,
Int(value),
objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
func setup(for indexPath: IndexPath) {
self.row = indexPath.row
self.section = indexPath.section
}
var indexPath: IndexPath {
return IndexPath(row: row, section: section)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment