0

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

Esclapyus
  • 9
  • 2
  • How are you moving data back with a segue? That sounds like you are doing segues incorrectly. There is no single answer to this. Yes, use a singleton, use a delegate, use a protocol, use a redux data store, use core data, the answer to this question is up to you. That’s all part of designing and developing an app. – Fogmeister Apr 08 '18 at 18:19
  • 1
    Note that storyboards and segues are a relatively recent addition to iOS in general. What have you tried so far? Also... “I don’t read objective c” is a poor excuse. It should not matter what language it is. The main idea is the iOS implementation of it. – Fogmeister Apr 08 '18 at 18:20
  • @rmaddy it’s not a duplicate, the question and answers in the other one uses storyboard and segues. – Esclapyus Apr 09 '18 at 04:31
  • There are many answers in the duplicate. Many do not use storyboards or segues. Many are in Swift. – rmaddy Apr 09 '18 at 04:33

0 Answers0