outfoxx / swiftpoet

Kotlin and Java API for generating .swift source files.
Apache License 2.0
277 stars 26 forks source link

Add support for subscript properties #76

Closed kdubb closed 1 year ago

kdubb commented 1 year ago

Fixes #69

kdubb commented 1 year ago

@lickel This implements subscript properties in all their Swift glory. Use have to use a FunctionSignatureSpec builder that allows you to create whatever crazy signature you need 😀

E.g.

PropertySpec
  .subscriptBuilder(
    FunctionSignatureSpec.builder()
      .addTypeVariable(typeVariable("P").withBounds(TypeVariableName.Bound(typeName("Swift.StringProtocol"))))
      .addParameter(
        "index",
        typeName("Swift.KeyPath")
          .parameterizedBy(typeName(".BackingData"), typeVariable("P"))
      )
      .returns(typeVariable("P"))
      .build()
  )
  .getter(...)
  .setter(...)
  .build()
lickel commented 1 year ago

that's awesome, thanks!