I’ve written a cross-platform C header defining an API. My team is writing bindings to this API in a number of languages including Java, C# and now Swift. For the most part it’s going smoothly, but I’ve found that the enum types I define in the API are translating oddly. For example:typedefenum {kDeleted = 0x01,kConflicted = 0x02,kHasAttachments = 0x04,kExists = 0x1000} C4DocumentFlags;translates to (as shown in the Xcode assistant editor):
publicstruct C4DocumentFlags : RawRepresentable, Equatable {
public init(_ rawValue: UInt32)public init(rawValue: UInt32)public var rawValue: UInt32}
publicstruct C4DocumentFlags : RawRepresentable, Equatable {
public init(_ rawValue: UInt32)public init(rawValue: UInt32)public var rawValue: UInt32}
(Yes, it appears twice.) It’s inconvenient that this turns into a struct instead of a Swift enum or just an integer type. But the biggest glitch is that the actual enum values (kDeleted, etc.) don’t appear in the Swift interface at all! This means that to actually use this enum I have to either redefine the constants in Swift or use hardcoded numbers, either of which is fragile.This seems like a bug in the C-interface-importer. I’m guessing that Apple put all their effort into fixing up their enum declarations to be Swift-friendly, and then didn’t consider how a plain C enum declaration translates…(Again, this is a cross-platform header, so I can’t just use CF_ENUM or NS_OPTIONS to declare these enums. I could add some fancy #ifdef APPLE stuff, but I’d rather not uglify the header too much.)—Jens
--You received this message because you are subscribed to the Google Groups "Swift Language" group.To unsubscribe from this group and stop receiving emails from it, send an email to swift-languag...@googlegroups.com.To post to this group, send email to swift-l...@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/9D89B424-0E1C-4C61-B26F-3D10E0DAE710%40mooseyard.com.For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/1446683359.3518631.429496177.2157834B%40webmail.messagingengine.com.