jarjar jarjar - 1 year ago 91
Swift Question

UICollectionView's cell registerClass in Swift

Right now I'm using NSClassFromString, but is there a better way to get an AnyClass! from a class in Swift? I am trying to pass the reference to my collection view's -registerClass:forCellWithReuseIdentifier: method.

collectionView.registerClass(NSClassFromString("MyCoolViewCell"), forCellWithReuseIdentifier: "MyCoolViewCell")

Answer Source

This is currently just a blind but educated guess, but using Class.self might be what you want.

collectionView.registerClass(MyCoolViewCell.self, forCellWithReuseIdentifier: "MyCoolViewCell")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download