Lory Huz Lory Huz - 2 months ago 30
iOS Question

XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass

I encounter some issues on collectionView & collectionViewLayout on Xcode 8 + Swift 3 project.

It's seems some methods totally disappeared.

For example, when I subclass UICollectionViewFlowLayout:

override func layoutAttributesClass() -> AnyClass


This trigger xcode error:

Method does not override Any Method from his superclass


Documentation of this method:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionViewLayout_class/index.html#//apple_ref/occ/clm/UICollectionViewLayout/layoutAttributesClass

Not sure it's Xcode 8 related because I already have strange issues with collectionView on Xcode 7 and swift 2.3, for example, itemSizeAtIndexPath method is not detected on xcode but if I put the method in a collectionViewController it's called even without the keyword override.

Answer

In Swift 3, it is a (class) property instead of a method:

override class var layoutAttributesClass: AnyClass {
    // ...
}