ios - Pass a class to other class SWIFT -
i pass class class b , call method backwards class a. i'm not sure if understand me.
class a:
public func showalertfor() { let secondcontroller = secondcontroller() var alert : uialertcontroller = secondcontroller.showalertfortranslate( **????** ) self.presentviewcontroller(alert, animated: true, completion: nil) } public func dosomething { println("dosomething") }
class b: (second controller)
public func showalertfortranslate( **????** ) { **????**.dosomething() // other stuff }
this how call function class b , b a:
class a{ func foo(){ println("a foo"); } func tellbtocallfoo(){ var myb = b() myb.foothea(self); } } class b{ func foothea(mya : a){ mya.foo(); } } var mya = a(); mya.tellbtocallfoo()
you can work protocols
protocol mycustomprotocol { func mycallbackfunction(); } class : mycustomprotocol{ func mycallbackfunction(){ println("i a") } } class b : mycustomprotocol{ func mycallbackfunction(){ println("i b") } } class c{ func dosomethingwithmycustomprotocol(mcp : mycustomprotocol){ mcp.mycallbackfunction(); } } var mya = a(); var myb = b(); var myc = c(); myc.dosomethingwithmycustomprotocol(mya); myc.dosomethingwithmycustomprotocol(myb); //output: //i //i b
Comments
Post a Comment