In Objective-C we use to do it like this
+ (Class)layerClass
{
return [CAEAGLLayer class];
}
Obviously this won\'t work:
CA
Swift does introspection much differently than Objective-C. You may want to take a look at the docs about Metatypes.
For your case I'd try: CAEAGLLayer.self
In iOS 10, this is a calculated property instead of a method:
override class var layerClass: AnyClass {
get {
return CAEAGLLayer.self
}
}
Adapted from Apple's ListerKit sample code:
override class func layerClass() -> AnyClass {
return CAEAGLLayer.self
}
Update for Swift 3:
override class var layerClass: AnyClass {
get {
return CAGradientLayer.self
}
}
It can be written like this
import UIKit
class GradientView: UIView {
override final class var layerClass: AnyClass {
return CAGradientLayer.self
}
}
Bonus tip: Maybe you would like to have a type safe getter to the layer? Then you can write
import UIKit
class GradientView: UIView {
override final class var layerClass: AnyClass {
return CAGradientLayer.self
}
override var layer: CAGradientLayer {
return super.layer as! CAGradientLayer
}
}