I'm trying to work through this tutorial: https://cocoacasts.com/implement-the-nsfetchedresultscontrollerdelegate-protocol-with-swift-3
But I found him using the Storyboard
and segues
to move data between ViewControllers
. Yet I can not find a proper and safe way to move data from one UIViewController
and another.
Everyone always throws around 'oh you just need a delegate and protocol' or 'use singletons' or 'please never use singletons'. All I could find in the last six hours of reading on protocols and delegates are superficial examples of weddings, puppies and tanks, but nowhere a proper way to do this. The only thing I could find is in objective-C, which I sadly don't read or write. Even the questions on Stackoverflow that asked the same question don't have the answer, since the explanation is usually vague and in the category of 'I do it like this because it works, you too should do it like this. It works now.', without further explanation.
Now moving something towards a VC when you use the present()
function is easy, but backwards is the real problem, since the same trick doesn't work when you use dismiss()
or popViewController()
.
Nowhere can I find a proper way to move data (like in the tutorial's case an NSManagedObjectContext object) between VCs with delegates and protocols.
Surely I'm not the only one wondering, and a good explanation of the different ways with some example code would be helpful for others than me as well.
So my questions remain: How do you move information between viewControllers without Storyboard and without Segues in Swift? And if delegates and protocols are the answer, what is the proper way to do this?
EDIT: it is different from the other question on this topic (Passing Data between View Controllers) because this question is asked in Swift, not in Objective-C