Gxp
Gxp

Reputation: 35

how to use property layoutAttributesClass of UICollectionViewLayout?

i found property layoutAttributesClass's availability is sdk 10 or later,however i wrote

+ (Class)layoutAttributesClass
{
    return [MyCollectionViewLayoutAttributes class];
}

in my customed UICollectionViewFlowLayout class, when tested on my phone(sdk 9) this function was called.so how to understand the availability of sdk and when this function will be called? thanks in advance.

Upvotes: 1

Views: 254

Answers (3)

Rizwan Shaikh
Rizwan Shaikh

Reputation: 271

Below is code for determine whether class is available in the SDK or not

if ([UICollectionViewLayoutAttributes class]) 
{
//Write your code here that you want when the class is available for that sdk.    
}

Upvotes: 0

rob mayoff
rob mayoff

Reputation: 385540

The documentation is misleading. The +[UICollectionViewLayout layoutAttributesClass] method has been publicly supported since iOS 6.0, when UICollectionViewLayout was introduced.

Class properties were introduced in Xcode 8, which was released with iOS 10. At that time, layoutAttributesClass was changed to be a class property, instead of just a class method. This change means it's imported into Swift as a class property instead of as a class methods.

In Objective-C, you must still override it as a class method. The code you wrote is correct in all versions of iOS since 6.0.

Upvotes: 1

Morshed Alam
Morshed Alam

Reputation: 153

This property is available from iOS 8 or 9 but not from iOS 10. I think you can implement this from iOS 8 and later.

Upvotes: 1

Related Questions