ios - Swift - Instance "not constructible with '...." from "static" method -


When I try to install a class through the "static" method (required by the protocol), the compiler I do not recognize the initiator even though I pass the correct parameter.

Enter image details here

The problem is that you are defining a template called" comment "in your method declaration that is blurring the actual comment class to give you that template argument a different name Will happen.

And I believe that your JSONSerializable protocol is not defined by the way you want it. You can use Self in a protocol to refer to the class implementing the protocol, so there is no need for a template. Your protocol may look like this:

  Protocol JSON SerialJabal {class func instanceFrom (json: [string: AnyObject]) - & gt; Self; }  

Then you will apply this method to your comment class:

  class comment: JSONSerializable {... class func instanceFrom (json: [string : AnyObject]) - & gt; Comment {Return Comment (Message: "Lorem Laurem", Author: User ())}}  

However, in Slipper it is preferred to make initial use instead of class methods :

  Protocol JSONSerializable {init (json: [String: AnyObject]) Category Comment: JSONSerializable {... init (json: [string: AnyObject]) {}}  < / Pre> 

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -