Using C functions as Swift struct methods

See “Import as init” and “Import as static computed property” in SE-0044 Import as member. In your case that would be

typedef struct { int x; } Foo;

Foo Foo_maker (int x)
__attribute__((swift_name("Foo.init(_:)")));

Foo Foo_zero(void)
__attribute__((swift_name("getter:Foo.zero()")));

which can be used from Swift as

let foo = Foo(123)
let bar = Foo.zero
1 Like