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 Build a Self-Destructing Message iPhone App Capturing Photo and Video Using UIImagePickerController Adding Recipients

reardelt
reardelt
8,030 Points

I think self.relations should be defined in the viewWillAppear

If we logout and then log back in again with another user (without rerunning the simulator), we will get the other user's friends as the self.relations, from the earlier user, is still present.

2 Answers

Alexander Sims
Alexander Sims
656 Points

yep, I can clarify that this is a better way to architect the solution.
From my understanding of how the way the View life-cycle works, the self.relations will be cached until the app is destroyed from memory. If you log out and keep relogging in with different credentials with friends.relation in view did load. Then you will persistently see the previous users friends. Good spot :)

Stone Preston
Stone Preston
42,016 Points

the downside to this, however, is that you are making a network request every time the view appears which you probably dont want to happen.

You may want to add some logic in viewWillAppear to get the relation once, and only when the user pulls to refresh or new friends get added. You could accomplish this with NSNotification.

Then when the user logs off, broadcast another notification that clears the value of the relation and resets the logic in viewWillAppear so that the next tim the view appears the relation gets queried for again

Alexander Sims
Alexander Sims
656 Points

Thanks for the suggestion Preston, that does sound a much better way of doing it - will modify my code.

reardelt
reardelt
8,030 Points

Thanks Stone.