### Calling Objective-C via Generated Bindings (Go) Source: https://github.com/progrium/darwinkit/blob/main/README.md This Go snippet shows the same functionality as the previous example but using the higher-level, generated Go bindings provided by DarwinKit. It demonstrates a more idiomatic Go API for interacting with Objective-C frameworks like AppKit. ```go app := appkit.Application_SharedApplication() app.Run() ``` -------------------------------- ### Get Generated Framework Stats (Shell) Source: https://github.com/progrium/darwinkit/blob/main/docs/generation.md Executes a shell script to provide basic statistical information about the generated frameworks within the project. ```shell ./generate/tools/stats.sh ``` -------------------------------- ### Initializing Go Module and Running DarwinKit App Source: https://github.com/progrium/darwinkit/blob/main/README.md These shell commands initialize a new Go module named 'helloworld', fetch the DarwinKit dependency at the 'main' branch, and then execute the 'main.go' program. This prepares the project and runs the macOS application built with DarwinKit. ```Shell go mod init helloworld go get github.com/progrium/darwinkit@main go run main.go ``` -------------------------------- ### Creating macOS Window with WebView using DarwinKit Go Source: https://github.com/progrium/darwinkit/blob/main/README.md This Go snippet initializes a macOS application using DarwinKit, sets its activation policy, creates a window with a specified frame, and adds a WebView loading a URL. It also configures the application to terminate when the last window is closed. ```Go package main import ( "github.com/progrium/darwinkit/objc" "github.com/progrium/darwinkit/macos" "github.com/progrium/darwinkit/macos/appkit" "github.com/progrium/darwinkit/macos/foundation" "github.com/progrium/darwinkit/macos/webkit" ) func main() { // runs macOS application event loop with a callback on success macos.RunApp(func(app appkit.Application, delegate *appkit.ApplicationDelegate) { app.SetActivationPolicy(appkit.ApplicationActivationPolicyRegular) app.ActivateIgnoringOtherApps(true) url := foundation.URL_URLWithString("https://github.com/sponsors/darwinkitdev") req := foundation.NewURLRequestWithURL(url) frame := foundation.Rect{Size: foundation.Size{1440, 900}} config := webkit.NewWebViewConfiguration() wv := webkit.NewWebViewWithFrameConfiguration(frame, config) wv.LoadRequest(req) w := appkit.NewWindowWithContentRectStyleMaskBackingDefer(frame, appkit.ClosableWindowMask|appkit.TitledWindowMask, appkit.BackingStoreBuffered, false) objc.Retain(&w) w.SetContentView(wv) w.MakeKeyAndOrderFront(w) w.Center() delegate.SetApplicationShouldTerminateAfterLastWindowClosed(func(appkit.Application) bool { return true }) }) } ``` -------------------------------- ### Generate Go Structs for Framework (Shell) Source: https://github.com/progrium/darwinkit/blob/main/docs/generation.md Runs a Go tool to generate Go struct definitions with documentation for the specified framework. The output is redirected to a file within the framework's directory. ```shell go run ./generate/tools/structs.go foundation > ./macos/foundation/foundation_structs.go ``` -------------------------------- ### Initialize DarwinKit Module (Shell) Source: https://github.com/progrium/darwinkit/blob/main/docs/generation.md This command uses the Go run tool to execute the initmod script. It creates the necessary directory structure for a specified framework if it doesn't exist and populates it with initial non-generated files. The framework must be defined in the ./generate/modules directory. ```shell go run ./generate/tools/initmod.go macos appkit ``` -------------------------------- ### Generate All Framework Code with Go Source: https://github.com/progrium/darwinkit/blob/main/docs/generation.md Runs the code generation process for all packages under the current directory using `go generate`. This is used to generate bindings for all frameworks within the project. ```Shell go generate ./... ``` -------------------------------- ### Generate Specific Framework Code with Go Source: https://github.com/progrium/darwinkit/blob/main/docs/generation.md Runs the code generation process specifically for the `appkit` framework package using `go generate`. This is the standard way to generate bindings for a single framework. ```Shell go generate ./macos/appkit ``` -------------------------------- ### Lookup Symbols in symbolsdb (Shell) Source: https://github.com/progrium/darwinkit/blob/main/docs/generation.md Runs a Go tool to search the symbols database for entries whose path matches the given prefix. The output is piped to `jq` to filter for entries where the 'Kind' property is 'Framework'. Useful for inspecting the structure and content of the symbols database. ```shell go run ./generate/tools/lookup.go appkit | jq 'select(.Kind == "Framework")' ``` -------------------------------- ### Calling Objective-C Runtime Directly (Go) Source: https://github.com/progrium/darwinkit/blob/main/README.md This Go snippet demonstrates how to interact with Objective-C objects and methods directly using the low-level 'objc' package. It shows calling the 'sharedApplication' method on the 'NSApplication' class and then the 'run' method on the returned application object. ```go app := objc.Call[objc.Object](objc.GetClass("NSApplication"), objc.Sel("sharedApplication")) objc.Call[objc.Void](app, objc.Sel("run")) ``` -------------------------------- ### Generate Specific Framework Code with Go Source: https://github.com/progrium/darwinkit/blob/main/docs/generation.md Runs the code generation process for a specific framework package using `go generate`. This command is typically invoked via a `go:generate` directive in the framework's source file. It attempts to generate Go code bindings for the native framework. ```Shell go generate ./macos/your-framework ``` -------------------------------- ### Test Generated Framework Code with Go Source: https://github.com/progrium/darwinkit/blob/main/docs/generation.md Runs the Go tests for a specific framework package after code generation. This is crucial to check if the generated code compiles and to identify missing types, particularly structs. ```Shell go test ./macos/your-framework ``` -------------------------------- ### Running Enum/Constant Export Tool (Go) Source: https://github.com/progrium/darwinkit/blob/main/generate/modules/enums/README.md Executes the `enumexport.go` tool to generate value dumps for enums and constants from defined modules. This process is separate from binding generation and should be run on an x86 Mac for comprehensive value capture. The generated data is used by the code generation process. ```Shell go run ./generate/tools/enumexport.go ``` -------------------------------- ### Find Type Symbols in symbolsdb (Shell) Source: https://github.com/progrium/darwinkit/blob/main/docs/generation.md Runs a Go tool to search the symbols database for type symbols matching the specified name. The output can be further processed using tools like `jq`. ```shell go run ./generate/tools/type.go NSWindow ``` -------------------------------- ### Export All Framework Enums with enumexport Tool Source: https://github.com/progrium/darwinkit/blob/main/docs/generation.md Runs the `enumexport` tool without arguments to generate enum files in `./generate/modules/enums` for all known frameworks. This updates the entire enums database based on the current platform's values. ```Shell go run ./generate/tools/enumexport.go ``` -------------------------------- ### Regenerate Frameworks (Shell) Source: https://github.com/progrium/darwinkit/blob/main/docs/generation.md Executes a shell script to re-generate the code for frameworks that have previously been generated, typically identified by the presence of .gen.go files. Requires specifying the platform. ```shell ./generate/tools/regen.sh macos ``` -------------------------------- ### Export Framework Enums with enumexport Tool Source: https://github.com/progrium/darwinkit/blob/main/docs/generation.md Executes the `enumexport` tool for a specific framework (e.g., `appkit`) and pipes the output to a file. This generates a program that outputs constant and enum values found on the current platform, useful for updating the enums database. ```Shell go run ./generate/tools/enumexport.go appkit > ./generate/modules/enums/macos/appkit ``` -------------------------------- ### Check Declarations with declcheck Tool Source: https://github.com/progrium/darwinkit/blob/main/docs/generation.md Runs the `declcheck` tool against symbol declarations for a specified framework (e.g., `appkit`) using the symbols database. This helps validate the parsed declarations. ```Shell go run ./generate/tools/declcheck.go appkit ``` -------------------------------- ### Show Constant Value with constant Tool Source: https://github.com/progrium/darwinkit/blob/main/docs/generation.md Uses the `constant` tool to display the value of a specific constant (e.g., `NSWindowBelow`) for a given platform and framework (e.g., `macos`, `appkit`) from the internal enums database. ```Shell go run ./generate/tools/constant.go macos appkit NSWindowBelow ``` -------------------------------- ### Defining SymbolsDB JSON Schema - Go Source: https://github.com/progrium/darwinkit/blob/main/docs/generation.md Defines the Go struct representation for the JSON schema used by the symbolsdb. This schema describes various properties of an Apple framework symbol, including its name, kind, description, platform availability, and declaration details. It includes nested structs for platform information and function/method parameters. ```Go type Symbol struct { Name string Path string Kind string Description string Type string Parent string Modules []string Platforms []Platform Declaration string Parameters []Parameter Deprecated bool } type Platform struct { Name string IntroducedAt string Current string Beta bool Deprecated bool DeprecatedAt string } type Parameter struct { Name string Description string } ``` -------------------------------- ### Remove Auto-Generated Files with clobbergen Tool Source: https://github.com/progrium/darwinkit/blob/main/docs/generation.md Executes the `clobbergen` tool to remove all files within a specified path (e.g., `./macos/appkit`) that contain the auto-generated banner. Useful for cleaning up generated code. ```Shell go run ./generate/tools/clobbergen.go ./macos/appkit ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.