ios - Cannot assign to property in protocol - Swift compiler error -


i'm banging head against wall following code in swift. i've defined simple protocol:

protocol nameable {     var name : string { set } } 

and implemented with:

class nameableimpl : nameable {     var name : string = "" } 

and have following method in file (don't ask me why):

func namenameable( nameable: nameable, name: string ) {     nameable.name = name } 

the problem compiler gives following error property assignment in method:

cannot assign 'name' in 'nameable'

i can't see i'm doing wrong... following code compiles fine:

var nameable : nameable = nameableimpl() nameable.name = "john" 

i'm sure it's simple i've overlooked - doing wrong?

@matt's anwer correct.

another solution declare nameable class protocol.

protocol nameable: class { //               ^^^^^^^      var name : string { set } } 

i think, solution more suitable case. because namenameable useless unless nameable instance of class.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -