[ https://issues.apache.org/jira/browse/THRIFT-3773?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15484987#comment-15484987 ]
ASF GitHub Bot commented on THRIFT-3773: ---------------------------------------- Github user apocolipse commented on the issue: https://github.com/apache/thrift/pull/1084 @ChristopherRogers @fumoboy007 I implemented union support with enums, here's an example of generated code: ``` union TestUnion { 1: i32 data, 2: string message, 3: bool success } ``` ```swift public enum TestUnion { case data(val: Int32) case message(val: String) case success(val: Bool) } public func ==(lhs: TestUnion, rhs: TestUnion) -> Bool { return { switch (lhs, rhs) { case (.data(let lval), .data(let rval)): return lval == rval case (.message(let lval), .message(let rval)): return lval == rval case (.success(let lval), .success(let rval)): return lval == rval default: return false } }() } extension TestUnion : CustomStringConvertible { public var description : String { var desc = "TestUnion." switch self { case .data(let val): desc += "data(val: \(val))" case .message(let val): desc += "message(val: \(val))" case .success(let val): desc += "success(val: \(val))" } return desc } } extension TestUnion : Hashable { public var hashValue : Int { let prime = 31 var result = 1 switch self { case .data(let val): result = prime &* val.hashValue case .message(let val): result = prime &* val.hashValue case .success(let val): result = prime &* val.hashValue } return result } } extension TestUnion : TStruct { public static var fieldIds: [String: Int32] { return ["data": 1, "message": 2, "success": 3, ] } public static var structName: String { return "TestUnion" } public static func read(from proto: TProtocol) throws -> TestUnion { _ = try proto.readStructBegin() var ret: TestUnion? fields: while true { let (_, fieldType, fieldID) = try proto.readFieldBegin() switch (fieldID, fieldType) { case (_, .stop): break fields case (1, .i32): ret = TestUnion.data(val: try Int32.read(from: proto)) case (2, .string): ret = TestUnion.message(val: try String.read(from: proto)) case (3, .bool): ret = TestUnion.success(val: try Bool.read(from: proto)) case let (_, unknownType): try proto.skip(type: unknownType) } try proto.readFieldEnd() } if let ret = ret { return ret } throw TProtocolError(error: .unknown, message: "Missing required value for type: TestUnion") } } ``` > Swift Library > ------------- > > Key: THRIFT-3773 > URL: https://issues.apache.org/jira/browse/THRIFT-3773 > Project: Thrift > Issue Type: New Feature > Components: Swift - Library > Reporter: Thomas Bartelmess > > We already have the option to generate Swift code in the Cocoa compiler, > however large parts of the (Objective-C) Cocoa Library still depend on Cocoa > and Objective-C. > It would be good to have a native Swift library that doesn't depend on the > Cocoa libraries. > Design goals: > - Fully compatible with the code that is currently generated by the Cocoa > compiler (both Objective-C and Swift). > - Ability to run on Linux > - Pure Swift, no Objective-C code. > - No dependencies on closed source apple libraries > - Keep the same interface, so that the library is compatible with the code > the current cocoa compiler generates > - Better server support that the current Objective-C library. > - Follow the new Swift packaging format to be compatible with the Swift > Package manager -- This message was sent by Atlassian JIRA (v6.3.4#6332)