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

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -