/objective-zig

Runtime and bindings to common Objective-C frameworks.

Primary LanguageZigMIT LicenseMIT

Objective-C bindings to Zig (objective-zig)

License

Important

These bindings are work in progress. They may not function correctly or have a nasty api. Expect major changes to the runtime and how that impacts the frameworks.

objective-zig is a work-in-progress Objective-C runtime and auto generated collection of Objective-C frameworks in zig. You can find the bindings generator at objective-zig-gen. These bindings are not ready. See the notice at the bottom of the README.

The runtime is based off of other Zig Objective-C runtimes (objz, zig-objc, and mach_objc).

Frameworks

Example: Creating a window

const objz = @import("objective-zig");
const app_kit = objz.app_kit;
const foundation = objz.foundation;

pub fn main() void {
    const autorelease_pool = objz.autoreleasePoolPush();
    defer objz.autoreleasePoolPop(autorelease_pool);

    // Create the shared application.
    const app = app_kit.Application.sharedApplication().?;

    // Spawn a 1280 x 720 window in the bottom left corner.
    const rect = foundation.Rect{
        .origin = .{
            .x = 0,
            .y = 0,
        },
        .size = .{
            .width = 1280,
            .height = 720,
        },
    };

    // Create a window that has a title bar with a close button and is resizable.
    const style_mask = app_kit.WindowStyleMask_Titled | app_kit.WindowStyleMask_Closable | app_kit.WindowStyleMask_Resizable;
    const window = app_kit.Window.alloc().initWithContentRectStyleMaskBackingDefer(
        rect,
        style_mask,
        app_kit.BackingStoreType_Retained,
        .NO,
    );

    // Allocate a string and set the title of the window
    const title = foundation.String.alloc().initWithUTF8String("Hello World");
    window.setTitle(title);

    // Show the window and bring out.
    window.makeKeyAndOrderFront(null);

    // Run the event loop
    app.run();
}

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests if you want to help improve the project.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

  • Thanks to the Zig community for their ongoing support and inspiration
  • Inspiration for this project comes from the ened to bridge the gap between Zig and the Objective-C ecosystem.
  • Mach and mach-objc for giving me the initial inspiration, resources, and some runtime code bindings.