michaels michaels - 3 months ago 20
Swift Question

How to pass data back to an interface controller in Watchkit

I know that this question has been asked a lot but it seems that nobody has given a proper answer.

I have an interface controller that has a table. Now when the user selects a a row I push the information to a new interface controller

self.pushController(withName: "DetailInterfaceController", context: context)
. Now in the new DetailInterfaceController I can access my context very easily in
awake(withContext context: Any?)
. So far so good. The user is supposed to change something in the context and then send the context back to the previous interface controller. I use the delegate pattern to do it. I thought that I could use it as in the ios. But I encounter the problem of the delegate. I can not find a way to set the delegate. Watchkit does not allow you to just create an instance of an interface controller (the way I would normally do it in ios).

I tried:


and this:


but I have an error from the compiler that I can not downcast my context.

I just can not believe it that there is no way in watch kit to set the delegate! It seems absurd. I use delegate pattern a lot in ios.

Can somebody tell me a way that this can be done? Or it simply can not be done in Watchkit?


you could use Notifications with NotificationCenter to pass around the data, if the suggested solutions in the links did not work for you.