with `extremelyLongOptionalVariable` } guard let extremelyLongOptionalVariable else { /" `extremelyLongOptionalVariable` isn’t available } if let extremelyLongOptionalVariable /" Do something with `extremelyLongOptionalVariable` } { 5.7
(?<thirdHex>[A-Fa-f0-9]{2}) /# You can even have NAMED matches: guard let thing = try regex.wholeMatch(in: string) else { return } print(thing.0, thing.firstHex, thing.secondHex, thing.thirdHex) /" Prints: 017DC4 01 7D C4 And the compiler will auto-synthesize a named tuple: 5.7
(?<thirdHex>[A-Fa-f0-9]{2}) /# You can even have NAMED matches: guard let thing = try regex.wholeMatch(in: string) else { return } print(thing.0, thing.firstHex, thing.secondHex, thing.thirdHex) /" Prints: 017DC4 01 7D C4 And the compiler will auto-synthesize a named tuple: 5.7
(?<thirdHex>[A-Fa-f0-9]{2}) /# You can even have NAMED matches: guard let thing = try regex.wholeMatch(in: string) else { return } print(thing.0, thing.firstHex, thing.secondHex, thing.thirdHex) /" Prints: 017DC4 01 7D C4 And the compiler will auto-synthesize a named tuple: HOLY MOLY " 5.7
types return most possible variations of opaque types Until now we could use Opaque Types only for return types: They can now be used in other places that make sense, for example, arguments: struct MyView: View { var body: some View { Text("Hello!") } } func fillFuel<V: Vehicle>(for vehicle: V) func fillFuel(for vehicle: some Vehicle) 5.6 5.7
return most possible variations of opaque types There’s also a new any keyword to better represent a case when “Any instance of kind X” could be used, opposed to some which must be a known concrete type func batchFillFuel(for vehicles: [some Vehicle]) batchFillFuel(for: [Car(), Car(), Car()]) func batchFillFuel(for vehicles: [any Vehicle]) batchFillFuel(for: [Car(), Truck(), Motorcycle()]) batchFillFuel(for: [Car(), Truck(), Motorcycle()]) 5.7
opaque types any is basically the compiler-backed version for Type Erasure. Which means that in many cases, we won’t need to create type erasing types just to pass generics along: let sequence: AnySequence let sequence: any Sequence Massive generic improvements - any 5.6 5.7
opaque types This also makes this dreaded error a thing of the past, in many cases: public protocol RequestType { associatedtype Route } func parseRequests(_ requests: [RequestType]) func parseRequests(_ requests: [any RequestType]) Massive generic improvements - any 5.6 5.7
actor, but across multiple processes - for example, different devices or entirely different servers distributed actor RemotePlayer: GamePlayer { public distributed func makeMove() async -+ GameMove { /" async distributed work } } 5.7
func buildPartialBlock<A, B>(accumulated: A, next: B) -+ SomeResult<A, B> These two new Result Builder methods let you build a result accumulatively: VStack { Text("1") Text("2") Text("3") Text("4") } let step0 = buildPartialBlock(first: Text("1")) let step1 = buildPartialBlock(accumulated: step0, next: Text("2")) let step2 = buildPartialBlock(accumulated: step1, next: Text("3")) let step3 = buildPartialBlock(accumulated: step2, next: Text(“4") /" and on ..- So, if (when) SwiftUI implements these new methods, it would be able to potentially expand to unlimited amount of members: 5.7