delegation - Using delegate's methods when delegate is a UIViewController in Swift -


I'm not sure that this is a Xcode 6 swift-specific problem, but it goes here.

My representative is UIViewController, because UtilViewController is a representative asset type of UtilViewController, MyViewController and UtilViewController are designed to be used by viewcontrollers of all my apps. There is also a function creation order (), which will only be called by MyViewController because this function will be called only by MyViewController, inside the createOrder () is a line that calls the function declared by MyViewController, like it

  self.delegate! However, the UtilViewController throws an error in  
  The name of 'UIViewController' is not a member named 'methodInMyViewController'     Pre> 

How can I preserve the modularity of being a UIViewController rep, but also be able to call methods from their own viewcontrollers, which are the subclasses of UIViewController?

You can tell the compiler to put your representative in the form of a MyViewController that it is actually There is a MyViewController and he can call the method.

  (self.delegate! MyViewController) .methodInMyViewController ()  

Since the rep can not always be a MyViewController, so you might want to check that This is before casting:

  if self.delegate! MyViewController {(as self.delegate! MyViewController) .methodInMyViewController ()}  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -