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. Now that we know how to write data to Parse Server, we have to figure out how to read data from the Parse Server as well. Now, we have only one row here with apple and 100 calories. So, I'm going to change this to have two data at least. So, I'm going to go for banana and 150. So, if we run this one more time, then it will upload this data to the Parse Server so that if we go back to here and say 'Refresh' now we see the banana and 150 calories as well. Now, I have two rows here, two data. Now, how can we retrieve that data? Let me comment this out so that every time we run this it won't get uploaded to the database, okay? And we're going to do what we're going to do in here. So, first of all, in order to retrieve Parse objects, we use something called Parse Query, okay? So, this is how it looks like. So, we're going to create a query here, and this will be a PFQuery, and as you can see, this lets us retrieve data as PFObjects from a class, and if you open parentheses it will ask you for a class name, and in our case that's fruits. So, this has to be exactly the same. So, with a capitalized F, with a uppercase F, 'Fruit', okay? Then, we're going to specify if we want any filter right now, and I don't need any filter, I just want to get all data in my case, okay? We're going to see how to filter the result later on. If we say something like that .find, we will see some similar options that we have seen when we try to save objects. If we select find objects, it will do its synchronously, if we do it in background, we get one option with block and one option without block. And of course, we want something with block because we get to see the results in a PFObject array if we do that, or we get an error if there is any error, okay? And this is our objects in an array. So, we're going to have more than one objects in most of the cases and they will be given to us in an array, okay? So, if we do something like a for loop or any other operation that you might think of, we can get this object by one by one, okay? So, I'm going to call this object and this one error. Of course, I will check to see if error is not nil and if error is not nil, I'm just going to print out the error, okay? So, that we can keep track, else, I will just print out the objects. In most of the cases, you may want to do a for loop here. If you're going to get something out of that object, individual objects, but right now, I just want to see if we can get these objects. So, let me run this in our simulator and it will get the objects and printed in my log. So, let me see, here we go. We have the fruits class. We have the apple and 100 calories, and we have the banana with 150 calories. Of course, we have the additional columns as well like object ID, okay? So, that's good. Now I can use something like for loop to get individual objects, but let me show you how to filter the results. If you say .where, so this will ask you for a key and some condition. Something like if calories are actually equal to 100 or if calories are less than 100 or if calories are greater than 100 or you can go for name, of course, like you can just say something like name being equal to apple. Now if we run this from scratch, now we will see we only get the apple as you can see. We don't see banana because we filtered the results so that we only get the name being equal to apple. Of course, we can do something else like we can do query.whereKey, okay? And we can go for calories like calories less than two your calories greater than two, something like calories greater than 120. So, our calories in apple is actually 100, so we won't get that result, but rather we're going to get the banana and it's calories are actually greater than 120. So, if you need something to filter to results, you can actually use this whereKey and it's very similar to what we have done in the Firebase as well. Maybe you remember that we had this whereKey in the Firebase, but it's actually very easy to use in Parse so that you can do your retrieval operations very efficiently using these techniques. Right now we know how to write and we know how to read data using Parse database. That's actually all we need to work with Parse. Of course, we're going to learn how to create users, how to work with files like images so that we can upload images to this database. And when we deal with authentication, we're going to be saving information in this user class, and they all have their own methods. But before we dive into them, I'm going to go over and create, start creating my Foursquare Clone because right now our current information is sufficient to learn this along the way, okay? So, I'm going to stop here, and I will start working on my main storyboard and sign in page in order to understand how to work with authentication in Parse. That's what we're going to do 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.