The course is part of this learning path
This course explores maps and how we can integrate them into our apps. We'll leverage map functions like finding the user location, showing the user's location on the map, and choosing a location on the map to get its coordinates. And in order to do that, we're going to be focusing on an app called Travel Book. We're going to integrate Core Data in this Travel Book as well so that we can re-practice what we have learned in the previous section.
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
Prerequisites
To get the most out of this course, you should have some basic knowledge of iOS.
Hi, within this lecture, we're going to set up our app so that when we hit on this 'Add' button, it will display this exact same page that we're seeing right now. But when we click on the 'Eiffel Tower' or any other record, it will pass this information to the other ViewController and then we're going to get that information from the CoreData and display the details of the selected landmark or selected record in our Travel Book app. So, we're going to come over to 'ViewController' and we're going to have some selected name or selectedTitle variable in here in order to get the data from our ListViewController. So, we're going to use the same technique that we have seen in the previous section, okay? We're going to use prepare for a segue, we're going to use didSelectRow and we're going to pass that information in here. So, I'm going to say, 'selectedTitle' and this will be an empty string initially and 'selectedTitleID'. So, this will be a 'UUID?' optional. I'm going to pass those information from the ListViewController to this ViewController, okay? And in the viewDidLoad, I'm going to check to see if selectedTitle is not equal to an empty string. If it's not equal to, I'm going to go to 'CoreData' to get the related information. Else, I'm not going to do anything at all because I just want to show this ViewController as it is because our user is trying to create a new view, I believe. New record, I believe. So, I'm going to say, 'Add New Data'. So, in order to do that, we know how to do this, right? We're going to write the app, delegate again. We're going to get the ID and just filter the results according to that ID using NSPredicates. But we're not going to deal with those right now because first, we have to go to 'ListViewController' and we have to pass this information. And in the addButtonClicked, we're just going to send the selectedTitle as an empty string. And in here in the didSelectRow, we're not going to do that. We're just going to get the related information from the indexPath. So, let's call 'didSelectRow' and let's call 'prepare (for segue:'. Okay, so we have these two functions here. And let's create our 'chosenTitle' and this will be an empty string first. And again, 'chosenTitleId'. This will be an optional 'UUID?'. And let's come down. And if we click on this 'addButtonClicked', then it means that I'm going to say chosenTitle is an empty string. And in the didSelectRow, I'm just going to make sure that I do a segue, right? I'm going to perform a segue because eventually I'm going to the ViewController again. So, let's say, '"toViewController", sender: nil'. But, before we perform the segue, I have to make sure that chosenTitle is actually 'titleArray[indexPath.row]'. I'm going to do the same thing for the chosenTitleId as well. So, this will be 'chosenTitleId = idArray[indexPath.row]. And that's it for didSelectRow. I'm going to go for 'prepare (for segue:'. And in here, I'm going to check to see if segue.identifier is actually the toViewController, okay? If this is the case, this is the segue that I'm looking for. Then, I'm going to create the ViewController as a variable here. So, I'm going to say, destinationVC = segue.destination as! ViewController'. So, I'm going to cast this as my second ViewController. And then, if I do 'Command + B', it will get synchronized. So, when I say, 'destinationVC.', I will see the related options. So, what I'm looking for is not Latitude, Longitude but I'm looking for selectedTitle, okay. selectedTitle is actually chosenTitle and 'destinationVC.selectedTitleID = chosenTitleId'. This one. So, that's how we pass this information into the second ViewController. If we come over to ViewController, let's, right now, just create the 'stringUUID' and see if this works. Let's say that, 'let stringUUID'. And remember, we have to come over here and say, 'selectedTitleID.uuidString'. Now, I can print this out, 'print(stringUUID)'. And, in fact, let's make this not optional, okay, because we are certain that this won't be here because it's not empty string. And let me run this and see if everything's working out fine. So, if I hit on the 'Eiffel Tower', I won't see the details but I will see the UUID string as you can see here. So, let's go back and click on the second one. Here you go. We have another UUID. So, ID actually works. Now, of course, we have to get the related information from Core Data and display them in here as well. And if we click on this 'Add' button, it works as well. It brings up the empty name, empty text, empty map so that we can choose whatever we want. So, let's stop here and within the next lecture, we're going to get all of this data from Core Data and display them in our ViewController.
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.