Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift error: "class cannot be constructed because it has no accessible initializers"

Tags:

Xcode is giving me this error for my Swift code:

'myColor' cannot be constructed because it has no accessible initializers

import Foundation

protocol Prototype {
    func Clone<T>() -> T
}

class myColor: Prototype {
    var red: Int?
    var green: Int?
    var blue: Int?
    
    init () {}
    
    func Clone<myColor>() -> myColor {
        let newColor = myColor()
        newColor.red = self.red
        newColor.green = self.green
        newColor.blue = self.blue
        
        return newColor
    }
}

The error is on line:

let newColor = myColor()

Type 'myColor' has no member 'init'