Transferring Data
Start course
3h 18m

In this course, we're going to build a Foursquare Clone using Parse. Parse provides you with a great tool to work in cloud servers and you will learn the advantages and disadvantages that come with it.

Intended Audience

This course is designed for anyone who wants to:

  • Learn about iOS development and coding
  • Move into a career as an iOS developer
  • Master Swift skills


To get the most out of this course, you should have some basic knowledge of iOS.


Hi, within this lecture we're going to pass our information from PlacesViewController to DetailsViewController and the information that we're passing to is the place chosen, the ID of the place chosen because we're getting the name of the location and ID of the location, and when the user taps on that location, we're going to have to pass that ID so that we can use that ID to retrieve further information from Parse in the DetailsViewController. And we're going to use the old way of doing this. So, we're going to use the prepare for segue and pass this information because we're just passing one tiny little bit of data in here which is ID of the chosen location, okay? So, I'm going to call this prepare for segue, okay? And what we do here is to prepare the segue but also we have to call the didSelectRow as well so that we know which index was chosen, right? Of course, in order to make this work, we need some variables inside our DetailsViewController so that we can reach the DetailsViewController from here. And I'm going to call this chosenPlace. So, chosenPlaceId actually. This will be a string type object and you can try to make this initializer as an optional string or you can just create an empty string as well because it really doesn't matter. We're going to pass this information from our PlacesVC to here anyway, and you have seen the both ways of doing this so far, so I'm going to go for this empty string, okay? Under PlacesViewController, we're going to define our DetailsViewController as a variable and reach that information but in order to do that, of course, we need a segue. Right now I believe, yes, we have our segue right to DetailsViewController. Now we can use it. So, under prepare for segue, I'm going to check to see if segue identifier is actually toDetailsVC, right? If that's the case, then I'm going to create my DetailsVC as a variable. So, I'm going to say let destinationVC, destinationViewController is going to be segue.destination and I'm going to first cast this as my DetailsViewController and then later on I'm going to do a build with command B so that I can reach the variables of this destinationVC. And the variable that I want to get is the chosenPlaceId. So, if I say destinationVC. I will get to see this chosenPlaceId. And how will I get this chosenPlaceId? I have to create some other variable here so that I can get it. So, under here I'm going to say selectedPlaceId, and this will be an empty string initially, but once a user clicks on here, I'm going to assign its value. So, come over didSelectRow and I'm going to say selectedPlaceId is placeIdArray[indexPath.row]. And then later on we're actually going to perform the segue self.performSegue here. So, what was the segue identifier? It's toDetailsVC and the sender will be nil. So, that's it. That's how we pass this information in our places model, DetailsViewController. So, here let me try to print this and see if we can get these results. So, let me run this from scratch so that we can run this print statement as well. So, let me click on this James and here we go. Now we see this ID so we're going to use that ID to get the details from Parse server. So, let me import the Parse in DetailsViewController, okay? Under viewDidLoad rather than just printing out this result, I'm going to have another query in here. This time this will be again a PFQuery actually and the class name is again the places. This is all good, but this time I'm going to add a new whereKey to filter the results. So, I'm going to say query.whereKey and the key that I'm looking for is placeId, not placeId, let's see what it is. It's objectId, okay? So, objectId and this will be equal to chosenPlaceId. So, let's try this, let's say that query.findObjectsInBackground with block, okay? And this will give me an object and error. And if error is not nil, of course, I'm going to show some message again later on, else, I'm going to print out the objects for right now. Let's see if we can get the James restaurant ID, James restaurant details using that ID actually. Let's click on this James Restaurant and here we go. We get the James Restaurant details. Now, of course, we only have one value but it means that this is working right because we have a filter and we have the the results back. So, it must be working. Of course at the end of the section we're going to try this with another variables, and other rows and other values as well, don't worry. But right now we know that this is working and we have to parse this information. We have to actually process this information to show the name, the type, the atmosphere, the image and the coordinates to the user. Let's do that in the next lecture.


About the Author
Learning Paths

Atil is an instructor at Bogazici University, where he graduated back in 2010. He is also co-founder of Academy Club, which provides training, and Pera Games, which operates in the mobile gaming industry.

Covered Topics