Can I have an init func in a protocol?

Aaron Bratcher picture Aaron Bratcher · Sep 5, 2014 · Viewed 29.9k times · Source

When I try to implement my protocol this way:

protocol Serialization {
    func init(key keyValue: String, jsonValue: String)
}

I get an error saying: Expected identifier in function declaration.

Why am I getting this error?

Answer

newacct picture newacct · Sep 6, 2014

Yes you can. But you never put func in front of init:

protocol Serialization {
    init(key keyValue: String, jsonValue: String)
}