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

Ahmed Abdalla
Ahmed Abdalla
5,250 Points

Relating Users in Parse.com (Issue)

I am sure some of you may have noticed this issue;

See how we have the 'Friends' and 'Edit Friends' View controllers. When you click on 'Edit Friends' button, and you decide to add or remove a friend, in the instructor's videos he goes back to parse.com and shows how adding and deleting friends worked. But clicking on the '<Friends' back button on the top left corner after actually editing (on Edit Friends screen), will take you to the friends screen with the old values still in place (editing not picked up). Am I missing something ? Any thoughts ?

Cheers,

3 Answers

Stone Preston
Stone Preston
42,016 Points

That is the correct behavior at that point in the course. Later in the course you will move your code thats in viewDiDLoad into viewWillAppear so that the friends array is updated each time the view appears. You can fix it now if you want and implement viewWillAppear and move your code into that, or just wait a few more videos until he walks you through how to do that

Ahmed Abdalla
Ahmed Abdalla
5,250 Points

I thought I am getting ahead of myself. Thank you. Will try it out though :)

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

If anybody comes across this thread, you can view the solution at the 2:30 mark of this video. I'll also add a note about it in the Teacher Notes section for that video, too.

I've got a different "fix" which I'm leaning towards because I really hate the idea of triggering a back-end transaction every time we change navigation - especially here, as we are the ones that are updating the data. We know what the changes are.

This is what I implemented. Can you check to see whether there are any nasty problems with this?

1) In the FriendsViewController I changed the friends property from an NSArray to an NSMutableArray. This meant that when I set the property in the viewDidLoad method, I cast the NSArray object to NSMutableArray.

2) In the FriendsViewController prepareForSegue method, instead of using the arrayWithArray convenience constructor I simply set the property as: viewControllerFriends = self.friends

3) I've added the viewDidAppear method in FriendsViewController, but in it I've just put a [self.tableView dataReload] method so that the view itself will refresh with the updated value of the friends property.

So now I've done a pass by reference meaning that any changes I perform in the EditFriendsViewController property should be reflected in the FriendsViewController property and I get the advantage of not holding two sets of friends data in memory. Obviously the necessary back-end updates still occur.

Is this workable, or have I created a gap somewhere?

I've had another thought on this. We're reusing code for friends list in our CameraViewController. I'm thinking it might be even better to move the friends data into a central place where all views can access it.

By central place, I mean as a property of the AppDelegate or (perhaps better) in a separate NSObject subclass you create - eg. FriendsModel or similar. You could include an instance method to retrieve/refresh the data from Parse.com, save data to Parse.com and perhaps slightly nicer instance methods for retrieving and removing friends from the list.

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Yes, this is a great solution! Much cleaner separation of the model data, which is what we want to strive for. It's hard to fit all of this in our projects, so I'm glad you took it further. I'll try to do a better job going forward coming up with and explaining improvements that can be made. I'll also keep this in mind as a possible workshop.