generics - swift protocol init func error with SpriteKit -


can show me wrong code?

code in playground

error detail

protocol personwithname: class  {     var personname: string {get set}      init(name: string) }  class namecard<persontype: skspritenode persontype: personwithname> {      var person: persontype      init() {         self.person = persontype(name: "no name") // line error.     } } 

for shorter explanation replaced skspritenode any because have deal designated init() of skspritenode later in more detail.. more details on initializer requirements in protocols, take @ this section of apple's developer guide

protocol personwithname: class  {     var personname: string {get set}     init(name: string) }  class namecard<persontype: persontype: personwithname> {      var person: persontype      init() {         self.person = persontype(name: "no name")     } }  class exampleclass: personwithname {     var personname: string = ""      required init(name: string) {         personname = name     } }  var test = namecard<exampleclass>() print(test.person.personname) // "no name" 

Comments

Popular posts from this blog

Capture and play voice with Asterisk ARI -

c++ - Can not find the "fiostream.h" file -

visual studio - Installing Packages through Nuget - "Central Directory corrupt" -