Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

prepareForSegue VS. performSegueWithIdentifier

I am somewhat confused when it comes to when to use what?

I can use performSegueWithIdentifier to switch to another ViewController, and the prepareForSegue handles stuff you want to do BEFORE you actually switches to a ViewController?

2 Answers

Correct, prepareForSegue prepares data to passed between view controllers where as performSegue actually allows the switch to happen.

I'd like to know why use prepareforsegue if you can just store the data in a Dictionary?

It seems easier if you just initialize the dictionary in the first view controller and add/edit/remove from it in the subsequent view controller.

I'd like to know if this is a bad practice or will either work just fine?

I'm currently using a dictionary to pass data forward to view controllers.

Thanks in advance for your response.

I'd like to know the answer to this as well.