Passing Data Back

It’s my first time posting here but from the looks of it the community seems really supportive and organized - love it!

After years of giving up bc of constraints and other little things, I finally decided to try it Xcode again bc I’ve recently taken a course on IOS dev. So a quarter in I decided to test my knowledge and try a personal project. The journey has been roadblock after roadblock but I’ve surprised myself by persisting on and solving problems. Anyways enough jibber jab lol.

I’m struggling with passing data back. I know how to pass data forwards but vice versa has been a challenge.

My layout consist of:

  • Selection Bar Controller

    • FeaturedViewController

      • TableViewController

      • TableViewController

    • SearchViewController

    • BookmarksTableViewController

So currently I have cells that I can bookmark in the tableviewcontrollers, but that’s just about it. I want to place those bookmarks automatically inside the BookmarksTableViewController. So inside of my tableViewControllers I have back buttons that go back to the FeaturedViewController and I thought I’d pass the data back using this inside of the tableviewControllers once I go back to the Featured controller and then I’d pass that data back to the BookmarksTableViewController.

  let destinationFeatured = FeaturedViewController()
  destinationFeatured.bookmarks = bookmarks

but this idea didn’t work as I think its too simple probably for what I’m trying to do.

I’m struggling on this but I feel like its simple. I read somewhere that using a protocol and delegate would be good, but I’m so confused on that. I have a struct for the cells’ information so that’s good. But yeah I’m just so lost and I really want to learn. I don’t want to take code from the internet and just add it because it appears that’s what I need. I want to understand why I’m applying that idea to my code. Please help! Thank you guys!

Hi @G_Petty

Welcome to the community!

Let me see if I have what you are trying to do. You have a tableView which you can select certain rows to be bookmarked and you want just those bookmarked objects to fill a bookmark tableView in a new View. Yes?

Are you populating the original tableView via a database or JSON file? If the former, you could add a Bool for the bookmark and then populate the new tableView with objects that are marked true. If the latter, I will have to think about it, but before I do, I want to be sure I am on the right track.

Good for you with sticking to it! I have spent many a days pounding my head against the keyboard. Discovering is so awesome when you do break through. You WILL get this too!

Blessings,
–Mark

Hey Mark, thank you so much for replying! I’m populating the original tableView with a struct. I do have a member called hasBookmarked that is a boolean. So not really a database but I think similar.

Currently, I am checking if the cells are favorited with the boolean. If they are, then they’d be appended to an array called bookmarks. But yeah I don’t know if I’m passing the data back correctly. Because the bookmarked cells don’t show on the bookmarks tableViewController.

Thank you for the words of wisdom, Mark! It definitely is worth the while when you finally find the right solution!