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.sectionasInt 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.rowasInt 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

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift