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 trialreardelt
8,030 PointsI 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
656 Pointsyep, 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 :)
reardelt
8,030 PointsThanks Stone.
Stone Preston
42,016 PointsStone Preston
42,016 Pointsthe 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
656 PointsAlexander Sims
656 PointsThanks for the suggestion Preston, that does sound a much better way of doing it - will modify my code.