collectioviewcell assign row and column as tag swift
Problem:
I want to assign the section and row to the collectionview cell iOS swift
Solution:
private struct AssociatedKeys {
static var section = "section"
static var row = "row"
}
extension UICollectioViewCell {
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)
}
}
}
mycell.section = indexPath.section
mycell.row = indexPath.row
Comments
Post a Comment