Wednesday, July 27, 2022

Swift Tuple Overloads

Novall Swift:

Did you know with WeatherKit you can request any combination of data sets and it’s returned as a tuple?

This is great if you only need a subset of data!

Here I’m requesting to include the current weather and daily forecast, and I can extract just what I need.


let (current, daily) = try await location, including: .current, .daily)

Kyle Howells:

How is it doing this for 2,3+ items?

By just having 8 copies of the same method defined! Which also means 8 is props is your max.


If this sort of thing is something we are going to be living with for a while, then Apple needs to build in some sort of automatic coalescing into the documentation and Xcode auto complete because this is a very messy and confusing documentation experience.

Perhaps someday Swift will support variadic generics.


Comments RSS · Twitter

Leave a Comment