{"id":28194313,"url":"https://github.com/humansinput/cak","last_synced_at":"2025-05-16T13:12:07.813Z","repository":{"id":128773278,"uuid":"476020294","full_name":"humansinput/cak","owner":"humansinput","description":"Apple's Cocoa wrapped to be used directly from C","archived":false,"fork":false,"pushed_at":"2022-08-22T02:33:43.000Z","size":62,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T09:12:03.192Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/humansinput.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-03-30T19:18:24.000Z","updated_at":"2022-03-30T19:19:40.000Z","dependencies_parsed_at":"2023-08-25T07:49:31.133Z","dependency_job_id":null,"html_url":"https://github.com/humansinput/cak","commit_stats":null,"previous_names":["humansinput/cak"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humansinput%2Fcak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humansinput%2Fcak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humansinput%2Fcak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humansinput%2Fcak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/humansinput","download_url":"https://codeload.github.com/humansinput/cak/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254535800,"owners_count":22087399,"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":"2025-05-16T13:11:52.406Z","updated_at":"2025-05-16T13:12:07.807Z","avatar_url":"https://github.com/humansinput.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cak\n\n__Automatic Cocoa C bindings__\n\n*Copyright (C) Tim K 2018-2022. https://xfen.page/*\n\n## Building\n\nYou'll need:\n\n- Ruby 2.0+ (built-in in macOS)\n- Xcode Command Line Tools \n  - For Xcode 10+ (without the CLI tools), do this: ``export BASE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks`` \n\n```bash\ngit clone https://github.com/tenfensw/cak.git\ncd cak\n./bind.sh\n```\n\nThe resulting bindings are going to be in the ``bindings`` folder.\n\n## Usage\n\nCak basically creates wrapper C functions around Objective-C interface methods. All of them are named more or less like their original counterparts, except for the casing \u0026 ``CakOID\u003cinterface name?\u003e`` prefix.\n\nFor example, let's say you want to create a new instance of ``NSString`` from a UTF-8 C string. You would do it this way directly in ObjC:\n\n```objective-c\nNSString* myString = [[NSString alloc] initWithUTF8String:\"Greetings from ObjC!\"];\n```\n\nAnd using Cak:\n\n```c\nCakOIDRef myString = CakOIDNSStringInitWithUTF8String(CakOIDNSStringAlloc(), \"Greetings from Cak!\");\n```\n\nLooks clunky in C, but for a quirky project like this this will do (+ hey, at least the naming is intuitive cause it's preserved from the original methods) :P\n\nAnother example with ``NSURL`` taken from Apple's website:\n\n```objc\nNSURL* baseURL = [NSURL fileURLWithPath:@\"file:///path/to/user/\"];\nNSURL* URL = [NSURL URLWithString:@\"folder/file.html\" relativeToURL:baseURL];\nNSLog(@\"absoluteURL = %@\", [URL absoluteURL]);\n```\n\nWith Cak:\n\n```c\n// there is no @\"\" shorthand in C, obv, so we have to declare the original strings seperately first\nCakOIDRef originalPath = CakOIDNSStringStringWithUTF8String(\"file:///path/to/user/\");\nCakOIDRef pathToAppend = CakOIDNSStringStringWithUTF8String(\"folder/file.html\");\n\nCakOIDRef baseURL = CakOIDNSURLFileURLWithPath(originalPath);\nCakOIDRef URL = CakOIDNSURLURLWithStringRelativeToURL(pathToAppend, baseURL);\nconst char* absoluteURL = CakOIDNSStringUTF8String(CakOIDNSURLAbsoluteURL(URL));\n\nprintf(\"absoluteURL = %s\\n\", absoluteURL);\n\n// free the memory now\nCakOIDNSStringRelease(originalPath);\nCakOIDNSStringRelease(pathToAppend);\nCakOIDNSURLRelease(baseURL);\nCakOIDNSURLRelease(URL);\n```\n\nNotice that (obviously) Objective-C's ARC is not possible in C, so you have to manage memory with ``Retain`` and ``Release`` manually.\n\nTo link:\n\n```bash\n$ clang -o urldemo -I$PATH_TO_CAK_SOURCES/bindings -std=c99 -fno-objc-arc urldemo.c $PATH_TO_CAK_SOURCES/bindings/minifoundation.a\n```\n\nSee ``demo.c`` too for a fully working example.\n\n## Why does this project exist?\n\nThere are people who want to make Mac apps using native Apple technologies, but who also want to make their apps portable. At least one person like this exists and that's me.\n\nAlso making a project that allows people to make Mac apps in pure C sounds fun :P\n\n## License\n\nMIT, unless stated otherwise in the sources\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhumansinput%2Fcak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhumansinput%2Fcak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhumansinput%2Fcak/lists"}