Issue using protocol to connect two classes in swift language -
i utilize playground , seek message "show : hello" in below simple code. however, nil shows, there no compiler error. don't problem is.
protocol showsome{ func show(str:string) } class client: showsome{ var s: server? init(){ s = server(str: "hello", delegate: self) } func setup(){ allow server = s! server.service() } func show(str: string) { println("show: \(str)") } } class server{ allow delegate: showsome? allow str: string init(str: string, delegate: showsome){ self.delegate = delegate self.str = str } func service(){ allow d = delegate! d.show(str) } } var c = client() c.setup()
your code works me. have open timeline if in playground see output go println()
btw: conventions class names using camelcase initial big letter.
swift swift-playground
No comments:
Post a Comment