I wanted to play with unions imported from C in Xcode 7.1 beta 2, but can't get it to work. This is what the relase notes say:
"Field getters and setters are now created for named unions imported from C. In addition, an initializer with a named parameter for the field is provided. (19660119)"
And here's what I did:
- Create a OS X command line project in Xcode 7.1.
- Create a new C file and add it to the project. Say yes when Xcode asks you to create a bridging header.
- Add the following code to the C header (taken from the release notes):
typedef union IntOrFloat {
int intField;
float floatField;
} IntOrFloat;- Include the C header in the bridging header.
- In main.swift, try to create a variable of the union type:
let x = IntOrFloat(intField: 10) // error: Extra argment 'intField' in callAccording to the release notes, this should work, but it doesn't. If I look at the interface Swift generated for the C header, I get this:
public struct IntOrFloat {
public init()
}But it should look like this:
struct IntOrFloat {
var intField: Int { get set }
init(intField: Int)
var floatField: Float { get set }
init(floatField: Float)
}I can use the union normally in C code and call that C code from Swift, so I'm not sure what I'm doing wrong. Is this not fully functional yet in beta 2?