Error: "Generic types with parameter packs are experimental"

Code below from the video: Generalize APIs with parameter packs

protocol RequestProtocol {
  associatedtype Input
  associatedtype Output
  
  func evaluate(_ input: Input) -> Output
}

struct Evaluator<each Request: RequestProtocol> {
  var item: (repeat each Request)
  
  func query(
    _ input: repeat (each Request).Input
) -> (repeat (each Request).Output) {
    return (repeat (each item).evaluate(each input))
  }
}

The Evaluator declaration causes a compiler error, "Generic types with parameter packs are experimental". Is there a switch or flag to enable use of parameter packs?

  • Does, -enable-experimental-feature VariadicGenerics apply?

  • What is the correct means to apply -enable-experimental-feature VariadicGenerics to a Swift package? The flag seems to work when set in Swift Compiler - Custom Flags>Other Swift Flags in Build Settings of an iOS app.

Add a Comment

Accepted Reply

In the Package.swift file when declaring the target, include swiftSettings: [.enableExperimentalFeature("VariadicGenerics")].

Replies

In the Package.swift file when declaring the target, include swiftSettings: [.enableExperimentalFeature("VariadicGenerics")].