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
returning some FooProtocol is like we will tell the compiler that we will return “some sort of” generic type that has FooProtocol trait (some sort => opaque)
when we do this, compiler will infer the first returning type
another way to describe some in my understanding is:
some... is an opaque result type as introduced by SE-0244 and is available in Swift 5.1 with Xcode 11.
You can think of it as a
"reverse" generic placeholder
which is
satisfied by the implementation
rather than the caller.
func doSomething()->someSomeProtocol{}// is equivalent to:func doSomething<T:SomeProtocol>()->T{}
to me i just think of this way:
some FooProtocol
is like we will tell the compiler that we will return “some sort of” generic type that hasFooProtocol
trait (some sort => opaque)another way to describe
some
in my understanding is:"inferred generic return type"
==
reference: https://stackoverflow.com/questions/56433665/what-is-the-some-keyword-in-swiftui
==
So, opaque result types allow us to do several things:
https://www.whatsnewinswift.com/?from=5.0&to=5.1
==
note :
think of
some
Protocolas "some sort" of Protocol
SE-0244: https://github.com/apple/swift-evolution/blob/master/proposals/0244-opaque-result-types.md
==
https://blog.vihan.org/opaque-types-in-swift/
The text was updated successfully, but these errors were encountered: