I have the following protocol
in Swift
:
protocol FooConvertible{
typealias FooType
init(foo: FooType)
}
I can make Swift
classes conform to it in the class definition:
class Bar: FooConvertible {
var baz: String = ""
required init(foo: String){
baz = foo
}
}
So far so good. However, the problem arises when I try to make a class conform to it in an extension (With Cocoa classes, it's my only option, as I don't have the source):
class Baz {
var baz = ""
}
extension Baz: FooConvertible{
required convenience init(foo: String) { // Insists that this should be in the class definition
baz = foo
}
}
extension NSURL: FooConvertible{
required convenience init(foo: String) { // this also fails for the same reason
}
}
This used to be possible, in previous versions of the language
What's the reason it was removed?
That would mean that all the XXXLiteralConvertible Protocols are banned from Cocoa classes!
Any chance you are trying to create something like this:
Baz
will now know about all inits ofFooConvertible
. If so, I'm glad I could help. :)