Skip to content
Travis Cline edited this page Jul 6, 2023 · 1 revision

macdriver uses a code generator to help adding new Go wrappers to the Objective-C APIS.

We'll use NSPopover as an example for adding a new type.

First, install macschema and use it to fetch the API schema:

macschema pull appkit/NSPopover

Update the generator command gen/cmd/gen.go to include the new schema JSON file:

  // locate the appropriate Go package where this type belongs
  {"cocoa", []schemaLoader{
    // ...
    // insert a line to load the new schema definition:
    loadFile("api/appkit/nspopover.objc.json"),

Run the command to re-generate the code:

go run ./gen/cmd

Create a wrapper Go struct for the generated code: file cocoa/NSPopover.go:

type NSPopover struct{ gen_NSPopover }

// add helpers constructors and methods as-needed, e.g.:
func NSPopover_Init() NSPopover {
	return NSPopover_alloc().Init_asNSPopover()
}