Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you override layerClass in swift

Tags:

swift

In Objective-C we use to do it like this

+ (Class)layerClass
{
    return [CAEAGLLayer class];
}

Obviously this won't work:

CAEAGLLayer.class()

Because class is a keyword in Swift. How do you do it in Swift?

like image 588
chunkyguy Avatar asked Jun 22 '14 12:06

chunkyguy


3 Answers

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
    }
}
like image 199
David Anderson Avatar answered Oct 19 '22 19:10

David Anderson


In iOS 10, this is a calculated property instead of a method:

override class var layerClass: AnyClass {
    get {
        return CAEAGLLayer.self
    }
}
like image 28
savinola Avatar answered Oct 19 '22 19:10

savinola


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

like image 4
Connor Avatar answered Oct 19 '22 18:10

Connor