The course is part of this learning path
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.
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 add a new gestureRecognizer to our map to choose a location from the map. So, we have done this in the art book section, so I'm going to be a little bit fast, you know how to do that already. In fact, you can pause the video and try to do it on your own. So, I hope you managed to do that. So, what we do is to create a recognizer in here and this will be a UILongPressGestureRecognizer. So remember, we get this gestureRecognizer when the user presses for a long time over some view. So, this asks for an action and a selector. So, we have to create the selector. I'm going to call this chooseLocation, okay? And in this, actually in this chooseLocation, we're going to ask for a gestureRecognizer so that we will reach our UITapGestureRecognizer, remember, and this will actually give us opportunity to do something with that gestureRecognizer. And I'm going to call this chooseLocationgestureRecognizer and we have to give this some minimumPressDuration and I'm going to go for 3 as usual. And later on, I'm going to add this gestureRecognizer to my mapView. So, here we go. And of course, under this chooseLocation, we will start to check to see if this gestureRecognizer has actually began. So, how do we do that? We just say, if gestureRecognizer.state is a UIGestureRecognizer.state.began. So, if that's the case, remember what we do, remember we create some touched points. So, we're going to say let touches, and this will get, this will be gotten from the gestureRecognizer.location and it will ask us for a view and this is mapView. And again, we're going to create these coordinates out of that touches. So, I'm going to say, self.mapView.convert and we want something called converting points toCoordinatesFrom. So, we're going to convert this touch, this touched points into coordinates using our map. So, I'm doing this kind of fast because we have done this before and I explained what are those. So, if you don't know, I suggest you go back and watch as a refresher. So, let me create my annotation. So, my annotation will be MKPointAnnotation and the coordinates will be of course the coordinates, okay? And we get some errors over here. So, yep, this is called the mapView. Why are we getting that error? Because I misspelled it. Yap, this has to be mapView, and the annotation coordinate will be coordinates. Yep, we have just created that coordinates and we can give it some title and subtitle as well. Title could be the place name actually, not map name. Place name, so you can get that from PlaceModel.sharedInstance.placeName, right? And we have... we can have a subtitle as well. We can just write the place type here, like sharedInstance.placeType, okay? If you don't know what the subtitle and title of the annotation is, you're going to see in a minute. And later on, we're going to have to just add this annotation to our mapView, right? Because we have defined our coordinates, we have defined our title, subtitle, and everything. Yap, we are ready to say self.mapView.addAnnotation and we want to add our current annotation. So, that's it for annotation. That's it for choosing location. Okay, this will give us the coordinates and later on we're going to get these coordinates and we're going to get the current selected location's coordinates and get its latitude and longitude to save it to the parse. So, let me create a chosenLatitude and chosenLongitude over here. They will be doubles because we can actually have strings as well. We can just save our values as strings to the parse. You will see how we can do that. I'm going to show you, don't worry. And in here, I'm going to go for self.chosenLatitude and this will come from coordinates.latitude, okay? And this will give us some coordinates and we're going to convert it to string by saying this and I'm going to go for chosenLongitude. Again, strings, and coordinates.longitude. So, here we go, let's see. Let's try to transfer data from the art place View Controller, from here. So, let's say this is James Restaurant, okay? And this is going to be a restaurant. And for atmosphere, I'm just going to write something like nice and let's choose a picture so that it would be much more real. And in here, let me go over to Frank house and choose a location for James. So, let me hear it here for three seconds and here we go, we managed to add our annotation. So, if you click on that annotation, you will see James Restaurant and the restaurant. So, we managed to transfer the coordinates, not the coordinates, transfer the place name and place type so that now we are ready to get everything together and upload everything to the parse because right now we have our place name, place type, place atmosphere, we have our place image, we have our latitude, longitude, and everything. Now all we have to do is just create a PF object to save this information to the parse server. Let's do that in the next lecture.
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.