Why do I get this in Swift "cannot be constructed because it has no accessible initializers"
Even if you set your framework to public, you still need to declare all classes you want to make accessible as 'public'. Same goes for your init method.
public init() {
}
Did the trick for me.
First, classes have leading caps. Methods have leading lowercase. You mean MyColor
and clone()
.
You're confusing the compiler at this point:
func Clone<myColor>() -> myColor {
It thinks you mean that myColor
is a type variable that is shadowing the class name. So when you get to myColor()
, it's basically the same thing as T()
, which has no trivial constructor.
If you fix this stuff up, you'll find that the correct error is
Type 'MyColor' does not conform to protocol 'Prototype'
That error is a completely different problem. See Protocol func returning Self for an explanation of how to implement a copy protocol. You also may be interested in the followup: Swift protocol and return types on global functions.