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() -> some SomeProtocol {}
// 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
Protocol as "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/