{"id":13611892,"url":"https://github.com/mitchellh/zig-objc","last_synced_at":"2025-04-13T00:45:54.689Z","repository":{"id":65553272,"uuid":"584555420","full_name":"mitchellh/zig-objc","owner":"mitchellh","description":"Objective-C runtime bindings for Zig (Zig calling ObjC).","archived":false,"fork":false,"pushed_at":"2025-03-12T17:06:17.000Z","size":94,"stargazers_count":224,"open_issues_count":2,"forks_count":26,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-13T00:45:50.387Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mitchellh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-02T22:48:11.000Z","updated_at":"2025-04-06T02:32:46.000Z","dependencies_parsed_at":"2023-11-21T04:28:48.037Z","dependency_job_id":"e8c70cd0-5bad-4bb8-a821-293fd11f8191","html_url":"https://github.com/mitchellh/zig-objc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitchellh%2Fzig-objc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitchellh%2Fzig-objc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitchellh%2Fzig-objc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitchellh%2Fzig-objc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mitchellh","download_url":"https://codeload.github.com/mitchellh/zig-objc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650420,"owners_count":21139672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T19:02:17.645Z","updated_at":"2025-04-13T00:45:54.659Z","avatar_url":"https://github.com/mitchellh.png","language":"Zig","readme":"# zig-objc - Objective-C Runtime Bindings for Zig\n\nzig-objc allows Zig to call Objective-C using the macOS\n[Objective-C runtime](https://developer.apple.com/documentation/objectivec/objective-c_runtime?language=objc).\n\n**Project Status:** This library does not currently have 100% coverage over the Objective-C\nruntime, but supports enough features to be useful. I use this library in\nshipping code that I run every day.\n\n## Features\n\n  * Classes:\n    - Find classes\n    - Read property metadata\n    - Call methods\n    - Create subclasses\n    - Add methods\n    - Replace methods\n    - Add instance variables\n  * Objects:\n    - Class or class name for object\n    - Read and write properties\n    - Read and write instance variables\n    - Call methods\n    - Call superclass methods\n  * Protocols:\n    - Check conformance\n    - Read property metadata\n  * Blocks:\n    - Define and invoke blocks with captured values\n    - Pass blocks to C APIs which can then invoke your Zig code\n  * Autorelease pools\n\nThere is still a bunch of the runtime API that isn't supported. It wouldn't\nbe hard work to add it, I just haven't needed it. For example: object\ninstance variables, protocols, dynamically registering new classes, etc.\n\nFeel free to open a pull request if you want additional features.\n**Do not open issues to request features (only pull requests).** I'm\nonly going to add features I need, _unless_ you open a pull request to\nadd it yourself.\n\n## Example\n\nHere is an example that uses `NSProcessInfo` to implement a function\n`macosVersionAtLeast` that returns true if the running macOS versions\nis at least the given arguments.\n\n```zig\nconst objc = @import(\"objc\");\n\npub fn macosVersionAtLeast(major: i64, minor: i64, patch: i64) bool {\n    /// Get the objc class from the runtime\n    const NSProcessInfo = objc.getClass(\"NSProcessInfo\").?;\n\n    /// Call a class method with no arguments that returns another objc object.\n    const info = NSProcessInfo.msgSend(objc.Object, \"processInfo\", .{});\n\n    /// Call an instance method that returns a boolean and takes a single\n    /// argument.\n    return info.msgSend(bool, \"isOperatingSystemAtLeastVersion:\", .{\n        NSOperatingSystemVersion{ .major = major, .minor = minor, .patch = patch },\n    });\n}\n\n/// This extern struct matches the Cocoa headers for layout.\nconst NSOperatingSystemVersion = extern struct {\n    major: i64,\n    minor: i64,\n    patch: i64,\n};\n```\n\n## Usage\n\nAdd this repository to your `build.zig.zon` file. Then:\n\n```zig\npub fn build(b: *std.build.Builder) !void {\n  // ... other stuff\n\n  exe.root_module.addImport(\"obcj\", b.dependency(\"zig_objc\", .{\n    .target = target,\n    .optimize = optimize,\n  }).module(\"objc\"));\n}\n```\n\nNote that `zig-objc` will find and link to headers from the target SDK\n(macOS, iOS, etc.) automatically by finding your Xcode installation. If\nXcode is not installed, you can add it manually but you must set the\n`-Dadd-paths=false` flag.\n\n**`zig-objc` only works with released versions of Zig.** We don't support\nnightly versions because the Zig compiler is still changing too much.\n\n## Documentation\n\nRead the source code, it is well commented. If something isn't clear, please\nopen an issue and I'll enhance the source code. Some familiarity with\nObjective-C concepts is expected for understanding the doc comments.\n","funding_links":[],"categories":["Zig","Libraries","Interoperability"],"sub_categories":["FFI Bindings"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitchellh%2Fzig-objc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitchellh%2Fzig-objc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitchellh%2Fzig-objc/lists"}