Skip to content

Classes, Collection Literals, and More

Choose a tag to compare

@theoriginalbit theoriginalbit released this 11 Nov 21:30
· 39 commits to main since this release

What's new

Class declarations

Build and render classes with ClassDescriptor. Use the MemberAccessDescriptor.superMember(_:) convenience for describing super member access.

Collections

Array and dictionary literals can now contain expressions:

.array([
  .integer(1),
  .integer(1),
])
.array([
  .functionCall("resolveSetting"),
])
.dictionary([
  .init(key: .string("key"), value: .boolean(true)),
])

Note

Each element for arrays and dictionaries will always be output onto a new-line with a trailing comma.

New integer literals

Integer literals can be rendered in decimal, hexadecimal, octal, or binary using IntegerLiteral.

.integer(.decimal(1234)) // explicit form of .integer(1234)
.integer(.hexadecimal(0x4096Ee))
.integer(.octal(0o12345))
.integer(.binary(0b100))

Note

The integer value you provide does not need to match the decimal, hexadecimal, octal, or binary you wish to be rendered to the code; the compiler does not distinguish between how a literal is declared and is just provided as Int to SwiftStructureKit.

Commenting

DocC, inline comments, and mark comments now support Swift string interpolation.

Imports

  • Import descriptors support var and let imports
  • ImportDescriptor.foundation is a convenience for importing Foundation; the most common import.

Force unwrapping

Forced-value expressions render postfix !

.forcedValue(.identifier("value"))

Renders as value!.

Breaking changes and migration

  • StatementDescriptor.controlFlow is replaced by .controlTransfer. Update construction and switch patterns to use .controlTransfer.
  • LiteralDescriptor no longer conforms to Equatable. Its integer case now uses IntegerLiteral; integer construction such as .integer(42) remains available, but code that switches on literals cases will need to handle .decimal, .hexadecimal, .octal, and .binary.
  • If you switch exhaustively over ImportDescriptor.Kind, add handling for .var and .let.