AI-Assisted Development for iOS

Jul 18 2025 · Swift 6.1, iOS 18, Xcode 16.3

Lesson 03: Getting Started with Cursor

Fixing Errors

Episode complete

Play next episode

Next
Transcript

Now we’re going to take a look at how we can use cursor to debug problems. As we left the app last time, it built and it ran, but we get this error coming up saying an unexpected error occurred. So you can see here, clicking try again does nothing.

And so what we’re going to do is I’m just going to take a screenshot of this, save screen, and then I’m going to go to cursor. I’m going to grab that screenshot, I’m going to stick it into here and say that ran but came up with an error. Can you help please?

This says it launches, it shows an unexpected error. This is the catch all error handler. So I mean, that is quite useful in its own right is that it tells us in the weather view model. And we must have a catch all error handler. So where is the error? Case error is here like so. It’s basing it on the ViewModel state. And case here is that this view model is a text message from the error, which is coming from the view model.

And if we jumped into the ViewModel, then the error is unexpected error occurred which comes out of this process here of trying to get say, trying to get the weather. So it means it wasn’t an authorization denied and there wasn’t a timeout. So there has to be some other reason.

And then we can continue and it will tell us the same given the unexpected error shown. If the location fetch or weather API calls, there is an error that is not authorization denied or a localization timeout.

So how do you debug it? Didn’t ask for permission. It didn’t. Which means that the info list may be missing or was not included. Well, the info plist it created was not included. But we did add that thing in there. Check for networking. And check for parsing and data issues. The API returns data, but the data format is wrong.

So it reckons that there’s a missing info plist because it’s seen that I deleted it. And in fact is slightly pass-agg asking if I want to restore it. I will just check that that’s that hasn’t disappeared. So inside yesterday’s weather, Privacy location, When in use, Usage description, We need your location. Right? So there it is.

I’m pretty confident it didn’t ask. We’ll just run it again to confirm that. Oh, no, it does ask. I’m just being kind of going crazy. So I’m going to allow it once. I’m going to try again. All right. So it still has the unexpected error. Good, I’m just losing it before. So it did ask for permission and I granted it.

Okay, now, what does it reckon? So the info plist is not the issue. The weather view model has a generic catch to pinpoint the exact issue. We want to make this error handling more granular. That is what I would suggest. Yes. So it’s going to modify it to explicitly catch more specific errors from the weather API client.

And then it also reckons there’s some stuff that’s not in the Xcode project that I’m pretty confident is also false because otherwise it wouldn’t build. That’s this thing where cursor is not properly understanding the Xcode file.

So what we’ve got here is done. Those two. It’s now added a weather error. So there’s an unexpected one down here which is added the localized description. So we’ve got some idea it comes from. But it’s also now handling all of these weather errors. The invalid URL, the network error, the invalid response decoding it. All of these come from the weather API we saw before.

So let’s accept what we’ll hopefully see is little bit more detail in the error that comes back. So I’m going to jump over to Xcode, run this again and we’ll see what the error is this time.

So notice there that was writing code that you would you would write yourself. It was really helpful to do it for you and I actually I find it quite useful just to doing random debug strings as well in that sense.

I’m going to do what I did before is now given me a picture. So I’m going to grab a screenshot of it. I’m just going to drag that into that’s a new error. And hopefully now it’s much more helpful. Yes, well done. New weather API client receive data, but the Json decoder failed to pass it either because it was empty or malformed. The structs don’t perfectly match the API response Json structure.

Let’s inspect it. It’s going off and had a look at that. And it’s thought about it for eight seconds. What it’s doing here is so it’s still a little bit confused. What it’s doing now is again, exactly what I would do in this situation is adding some more detailed logging.

So it’s got in fact, if I jump over to the file that is added it to, it gets the HTTP response prints that out, and then it tries to decode it, and then it will write something else if it can’t decode it. So that will assume it will tell us what is the actual data we’re getting from the API. So let’s accept that.

Jump back to Xcode. Run this again. Allow okay. And now I’m not going to take a screenshot. I’m going to grab this. So it’s got the this is the logging. But it just added in a copy that I mean we can take a look at this and have a pretty good guess what the problem is. There’s an awful lot of nulls in here. Awful lot of nulls.

So I’m going to go back to cursor and say here’s the logging response and paste that in. All right. And it’s helpfully formatted that beautifully. Means that says a 200 response is fine. However, all of them are null. And we actually expect them to be non optional. So double int and double arrays.

So it can happen if it’s in the future. And there’s no no data available. It seems to think that the date 2025-06-08 is in the future relative to now. If you look at the clock in the top of the screen, it’s Monday, the 9th of June at 1415. I’m in the UK everywhere in the world is now past the 8th of June. So I don’t know. I mean, that’s just utter junk.

So moving on. That is not the problem. I do happen to know the problem is do with dates, but let’s see what its proposed solution is. So the first thing is that it’s going to allow it to receive null. Okay. Which is all right. I mean it’s not going to solve the problem. But if that’s I’m happy to accept that. Give us a different problem.

And then down here, it checks whether the data is available. And if not, it does this. It’s handling basically at handling all of the null responses that it’s got in there. So I’m going to save that. It’s essentially allowing NULL to come in from the API. It’s going to run that. I’m going to allow it. And now I have a new error.

Which I’m going to oh I dumped that in here as well. Probably put that here. New error. Let’s see what this comes back with. So at this point, like you should be looking much more carefully at what it’s doing. But I think it’s interesting to see what it will do.

So it thinks the problem is time string being parsed. The date formatter is expecting year year months month. But the API returns the a time okay. Leading to no date data for time. We already have. So it’s going to remove some debugging printing. All right okay.

I mean this is so in here it’s using a different time format and removing the debugging. I continue to be unconvinced, but let’s try it. Okay, so we got the same error. I’m continuing with this to see what happens. At this point, I would have gone and investigated why the API is returning NULL.

So now it’s added some logging and you can see a couple of bits of logging. Yeah, so I’ll accept that file. Go back to here. Run it again. Now we’re looking in the in the log to see what it says. It runs up. We’re going to allow it once we get that same error we get a lot of failed to parse time string.

So let’s copy this. Copy them into the cursor. Here’s the log. Now in, if you work on other platforms, for example, the web, then you can build tests and cursor can read the results of those tests, and it can read the results of what you’re doing. That’s significantly harder in iOS with Xcode. It’s possible, but much, much harder.

So we’re doing this quite manual in the person in the loop kind of cycle with some changes to Xcode, and this could become far more automated. Quite how automated it should be is a there’s a different question, right?

What’s it done now? Let’s just review the files. It’s changing the ISO format. It like the base one. It doesn’t like any of that. We’ve now got a date formatter is putting it. I could swear we started with something else that looks like this. And I mean, God knows this is massively overcomplicated, but okay, well, let’s accept it. Give that a go.

Right. Lovely. So now it’s yesterday’s weather. Here’s what the weather was like yesterday. At this time, I reckon zero degrees C, no precipitation with a clear sky. We’re putting things here in San Francisco, which is correct. And it’s the 18th of June at 1420. This is obviously not correct.

So we need to try and work out why that’s not correct. We’ve seen that the API’s returning nulls. We’ve not changed anything about the API. So it’s probably something to do with the API. We’re going to take a look at that in the next video, which is the next lesson where we’re going to use a new tool.

And we will then look at adding some tests for all this stuff, and hopefully we’ll end up with an app that will show you yesterday’s weather wherever you are at the current time. See you then.

See forum comments
Cinema mode Download course materials from Github
Previous: Debugging in an AI World Next: Conclusion