native icon indicating copy to clipboard operation
native copied to clipboard

[swift2objc] Generate bindings for enums

Open liamappelbe opened this issue 1 year ago • 2 comments

enum CompassPoint {
    case north
    case south
    case east
    case west
}

Enums are a bit complicated in Swift. There are simple enums like this one, and also enums with associated values.

liamappelbe avatar Jul 22 '24 01:07 liamappelbe

How does this play with the enum overhaul from earlier?

Levi-Lesches avatar Aug 08 '24 18:08 Levi-Lesches

swift2objc is a separate tool from ffigen, so it's not directly related.

image

I think if a Swift enum is simple enough that we can represent it as an ObjC/C enum, then it will make its way through to the Dart bindings just like any other enum. For the more complicated enums, we'll be generating classes that emulate the enums, and those will be represented in the Dart bindings as classes.

Later, we might be able to plumb some custom metadata through this pipeline to tell ffigen that a particular ObjC class is actually a representation of a Swift enum, and generate a Dart enum to wrap it, since Dart enums have many of the same features as Swift enums. That's not something I'm planning to do atm though.

liamappelbe avatar Aug 09 '24 00:08 liamappelbe