SE-0044 (
https://github.com/apple/swift-evolution/blob/master/proposals/0044-import-as-member.md
) describes how to annotate C functions with the swift_name attribute to tell
the Swift compiler how an API should be imported. There is an "Amendment: Also
allow for importing as subscript." but I could not make that part work.
This compiles and works as expected:
typedef struct Point3D {
float x;
float y;
float z;
} Point3D;
struct Point3D createPoint3D(float x, float y, float z)
__attribute__((swift_name("Point3D.init(x:y:z:)")));
// Import as method
struct Point3D rotatePoint3D(Point3D point, float radians)
__attribute__((swift_name("Point3D.rotate(self:radians:)")));
but
// Import as subscript
float Point3DGetPointAtIndex(int idx, Point3D point)
__attribute__((swift_name("getter:subscript(_:self:)")));
void Point3DSetPointAtIndex(int idx, Point3D point, float val)
__attribute__((swift_name("setter:subscript(_:self:newValue:)")));
causes compiler warnings
warning: 'swift_name' attribute for 'subscript' must take a 'self:'
parameter [-Wswift-name-attribute]
and the functions are not imported as a subscript getter/setter.
Is that not yet implemented, or is my syntax wrong?
Regards, Martin
_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users