I made a subclass of UICollectionViewCell and Swift is complaining that I'm not allowed to use superclass properties like bounds, backgroundView or selectedBackgroundView. This very code was given by Appleʼs documentation so I don't understand why it's disallowed.
I declared class MyCollectionViewCell: UICollectionViewCell method awakeFromNib.
Xcode 12.2 gives an error about bounds, backgroundView, and selectedBackgroundView saying stuff like "Instance member 'bounds' cannot be used on type 'MyCollectionViewCell'".
If I declare a variable as UICollectionViewCell I can set these properties in it, but a function in a subclass of UICollectionViewCell cannot access its own properties?
I declared class MyCollectionViewCell: UICollectionViewCell method awakeFromNib.
Code Block class MyCollectionViewCell: UICollectionViewCell { ... override class func awakeFromNib() { ... let redView = UIView(frame: bounds) redView.backgroundColor = colorLiteral(red: 1, green: 0, blue: 0, alpha: 1) self.backgroundView = redView let blueView = UIView(frame: bounds) blueView.backgroundColor = colorLiteral(red: 0, green: 0, blue: 1, alpha: 1) self.selectedBackgroundView = blueView
Xcode 12.2 gives an error about bounds, backgroundView, and selectedBackgroundView saying stuff like "Instance member 'bounds' cannot be used on type 'MyCollectionViewCell'".
If I declare a variable as UICollectionViewCell I can set these properties in it, but a function in a subclass of UICollectionViewCell cannot access its own properties?
The problem exists in this line:
The method awakeFromNib() which you want to override is an instance method, not a class method.
Remove the keyword class:
I do not understand why Xcode points this line with proper diagnostics, you should better send a feedback about this.
Code Block override class func awakeFromNib() {
The method awakeFromNib() which you want to override is an instance method, not a class method.
Remove the keyword class:
Code Block override func awakeFromNib() {
I do not understand why Xcode points this line with proper diagnostics, you should better send a feedback about this.