|
Hello everyone! I would like to know a few things. Here is all the code.
If we use the try? keyword and an error is thrown, the error is handled by turning it into an optional value. This means that there is no need to wrap the throwing method call in a do-catch statement. Since it throws an error here, why can't I use "try?" and why does it work without "try?"
I don't know where that ".main" came from.
Forgive me for my English. I realize I'm terrible at writing in English |
|
Nothing, really.
I don't understand what you are asking. You need some form of
|
|
I do not know how to explain it. I will try to write clearer.
I don't understand why in "guard let data" and "guard let loaded", we use "try?" and not in "guard let url". Only in this case, we don't use "try?", but why? I don't understand why once is "try?" and once it is not. Since it looks like the end result is the same |
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until February 9th. Sponsor Hacking with Swift and reach the world's largest Swift community! |
|
Hi! If I am not mistaken, those two functions with try you mentioned in your code are throwing functions i.e. decoder and data might throw errors. So for throwing functions you have to use try before them. As for url(forResource:) you don't need it as this is not throwing function.
|
|
Throwing functions can be handled in a So since That's why |
|
Developer ResponsibilityIt’s your responsibility, as a developer, to know about all these possibilities, and code your solutions effectively. Vanilla MethodsDevelopers (you, me, @twoStraws, Apple) may write methods or functions to perform a task. Some of these tasks do a lot of work, but do not return any data. Other functions may perform work then return data to you as an
Methods Returning OptionalsStill other functions may return
Throwing MethodsFinally, some methods may return data to you if everything works out ok. But if there’s a problem, the method will
|
|
After analyzing your answers, I finally understood why there is no "try?". But I have one more question. Why in "let astronauts" we use - "String: Astronaut" . But in " let missions" there is only -" Missions", without "String: ...." what is it caused?
Thank you in advance for your response :) |
|
Review Day 3 for more info on the difference between the two. |
|
I still don't understand it. I have two structures here
And the second structure
We use the same decoder for them
Then why "let astronauts" is a Dictionary, and " let missions" is Array. I know the differences between Dictionary and Array.
Thanks for the answer :) |
|
This is the power of generics. Here, we are using the same function to decode Take a look at the function declaration for
Arrays and Dictionaries are
Since This means we can use Using a generic function is essentially like having different functions for each type that you call it with, without having to actually write all those different functions. Well, how does
And if you look into the
Once again, if we sub in our types:
Okay, but how do we know we need |
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until February 9th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.