You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the function type (Void) -> Void is the same as (()) -> ()
If you use the former ((Void) -> Void) as a typealias, Swift warns. I am assuming things changed on a newer version but the docs were not updated?
// warning: when calling this function in Swift 4 or later, you must pass a '()' tuple; did you mean for the input type to be '()'?
typealiaswarningAlias=(Void)->Void
These types aren’t the same as () -> () — a function that takes no arguments.
But in the snippet that follows, all are true, meaning the types are same.
typealiasaliasOne=((Void))->VoidtypealiasaliasTwo=()->()typealiasaliasThree=(())->()typealiaswarningAlias=(Void)->Void
// all are true
print(aliasOne.self == aliasTwo.self)print(aliasTwo.self == aliasThree.self)print(aliasOne.self == aliasThree.self)
// all are still true, comparing with an alias that emits a warning
print(aliasOne.self == warningAlias.self)print(aliasTwo.self == warningAlias.self)print(aliasThree.self == warningAlias.self)
PS: All the quotes are taken from the aforementioned link and code snippets were run on Swift 5.10.
Correction
There is a chance I am just misunderstanding things, but I feel this part could be improved by not referring to a type ((Void) -> Void) that emits a warning and preferably explaining more on how they differ as the code snippet I have shown tells me (again, it could very well be a misunderstanding 🙂) that they do not differ.
Location
https://docs.swift.org/swift-book/documentation/the-swift-programming-language/types#Function-Type
Description
If you use the former (
(Void) -> Void
) as atypealias
, Swift warns. I am assuming things changed on a newer version but the docs were not updated?But in the snippet that follows, all are
true
, meaning the types are same.PS: All the quotes are taken from the aforementioned link and code snippets were run on Swift 5.10.
Correction
There is a chance I am just misunderstanding things, but I feel this part could be improved by not referring to a type (
(Void) -> Void
) that emits a warning and preferably explaining more on how they differ as the code snippet I have shown tells me (again, it could very well be a misunderstanding 🙂) that they do not differ.Edit: I have asked over at https://forums.swift.org/t/understanding-function-types/73349. I will close the issue if there is something wrong in my understanding, thanks and apologies 🙂
The text was updated successfully, but these errors were encountered: