Can I have an init func in a protocol?

Aaron Bratcher :

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?

newacct :

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

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I disable func init() autocomplete in GoSublime?

I can't await func() from __init__

How can I create a server Protocol class with an __init__ function?

Can I have a custom protocol on java type URL?

Why can not use protocol `Encodable` as a type in the func

How can I have my IDE recognize PHP call_user_func?

I have two inner class in class and i can't init class in swift

Do I have to override .__init__ in my subclass, or can I just add a few variables?

How a generic class to conform a protocol (that have init in it) with constraint?

Can't access to func() in parent VC via Delegate/Protocol

Why can't I pass a `func() []int` as `func() []interface{}` in go?

Protocol func returning Self

Mocking a Protocol with a Generic Func

In AJAX, do I have to init the class?

Can i use IEnumerator as Update func?

How can i actuate swap func in loop?

How can I get conditional protocol conformance with a protocol's parent?

How can I reference a protocol instance variable from a protocol method?

How can I create a protocol for a UITableViewCell?

Can I use a protocol array in ForEach?

How can I conform to ShapeStyle protocol in SwiftUI?

How can I assert a struct conforms to a protocol?

Can I use "HTTP authorization" in HTTPS protocol?

Can I force protocol conformation in Swift?

Can I replace a socket based protocol with gRPC?

How can I conform to the _BuiltInIntegerLiteralConvertible protocol?

Swift - Can I make a protocol Hashable?

How can I check whether the protocol is implemented?

Can I use `inout` with protocol extensions?