Check out my work on https://github.com/webdavis/webdavis
The more you know!
The more you know!
Since there are no associated value types the compiler says we can compare instances of this Error type and slaps on the Equatable protocol at compile time.
Since there are no associated value types the compiler says we can compare instances of this Error type and slaps on the Equatable protocol at compile time.
Here is an enum *with* associated value types:
Here is an enum *with* associated value types:
Somehow, the compiler is saying that RemoteFeedLoader.Error conforms to Equatable.
This led me to believe that the compiler was auto-synthesizing RemoteFeedLoader.Error's conformance to Equatable.
But what conditions need to be met in order for that to happen?
Somehow, the compiler is saying that RemoteFeedLoader.Error conforms to Equatable.
This led me to believe that the compiler was auto-synthesizing RemoteFeedLoader.Error's conformance to Equatable.
But what conditions need to be met in order for that to happen?
No where in this code did we explicitly conform the Error type to Equatable:
No where in this code did we explicitly conform the Error type to Equatable:
This means that the protocol's associatedtype Error need to conform to Equatable, which means that whatever class implements the protocol need to have an Equatable Error type.
This means that the protocol's associatedtype Error need to conform to Equatable, which means that whatever class implements the protocol need to have an Equatable Error type.
Whenever I commented out the following line in the interface boundary, I would then get the accompanying compile-time error in the test code:
Whenever I commented out the following line in the interface boundary, I would then get the accompanying compile-time error in the test code:
2. If it’s is a class-per-test framework (e.g. the JUnit approach) or not.
3. If the language supports interfaces/protocols. If not, then what does it use to achieve composition?
2. If it’s is a class-per-test framework (e.g. the JUnit approach) or not.
3. If the language supports interfaces/protocols. If not, then what does it use to achieve composition?
I said all this and realized that I didn't make it very clear that I am referring specifically to the "try?" syntax.
You can see it in the first code snippet as follows:
let root = try? JSONDecoder().decode(Root.self, from: data)
(I'M TIRED lol)
I said all this and realized that I didn't make it very clear that I am referring specifically to the "try?" syntax.
You can see it in the first code snippet as follows:
let root = try? JSONDecoder().decode(Root.self, from: data)
(I'M TIRED lol)
Maybe that's why the Swift team implemented this.
(Side note: I usually hate reading documentation, but the Swift team actually does a really good job at it.)
(7/7)
Maybe that's why the Swift team implemented this.
(Side note: I usually hate reading documentation, but the Swift team actually does a really good job at it.)
(7/7)
Now let's see what it would be like to implement the same behavior without this syntax. We could convert this to a do-catch block, like so:
Now let's see what it would be like to implement the same behavior without this syntax. We could convert this to a do-catch block, like so:
"You use try? to handle an error by converting it to an optional value. If an error is thrown while evaluating the try? expression, the value of the expression is nil."
(5/7)
"You use try? to handle an error by converting it to an optional value. If an error is thrown while evaluating the try? expression, the value of the expression is nil."
(5/7)
In this case we would rather throw our own domain-specific error. We don't care about the DecodingError thrown by decode().
So instead, if decode throws an error we instruct Swift to convert it to an optional value `nil`.
(4/7)
In this case we would rather throw our own domain-specific error. We don't care about the DecodingError thrown by decode().
So instead, if decode throws an error we instruct Swift to convert it to an optional value `nil`.
(4/7)