Skip to content

Playground to mess around with the opaque return type feature introduced in Swift 5.1

Notifications You must be signed in to change notification settings

lorin-vr/OpaqueReturnTypes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

OpaqueReturnTypes

Playground to mess around with the opaque return type feature introduced in Swift 5.1

Requirements

Xcode 11 or higher

Why would we want opaque result types?

  • We can use protocols as return types without worrying about Self or associated type requirements
  • We don’t have to expose internal types
  • In the future we can change the type we're returning without breaking anything outside
  • Our function is in charge of the type it returns, not the caller of the function (unlike with generics)
  • It's handy in SwiftUI because some View is much nicer than long, meaningless concrete types

References:

https://www.hackingwithswift.com/articles/187/how-to-use-opaque-return-types-in-swift-5-1 https://medium.com/@PhiJay/whats-this-some-in-swiftui-34e2c126d4c4

About

Playground to mess around with the opaque return type feature introduced in Swift 5.1

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages