{"id":25856871,"url":"https://github.com/lukaskollmer/objc","last_synced_at":"2026-02-27T13:31:58.286Z","repository":{"id":20096981,"uuid":"88511206","full_name":"lukaskollmer/objc","owner":"lukaskollmer","description":"🔮 NodeJS ↔ Objective-C bridge (experimental)","archived":false,"fork":false,"pushed_at":"2024-02-20T13:30:50.000Z","size":1601,"stargazers_count":104,"open_issues_count":20,"forks_count":20,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-10-19T19:44:54.866Z","etag":null,"topics":["node-ffi","nodejs","objc","objc-runtime"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/lukaskollmer.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","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":"2017-04-17T13:35:50.000Z","updated_at":"2025-09-12T19:06:54.000Z","dependencies_parsed_at":"2024-06-19T01:39:42.582Z","dependency_job_id":"c20d8f8f-d504-4a56-8664-b5afa9795ccf","html_url":"https://github.com/lukaskollmer/objc","commit_stats":{"total_commits":317,"total_committers":1,"mean_commits":317.0,"dds":0.0,"last_synced_commit":"cc4d6f0cb7475b29cdbf16b5662a3b302e36149b"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/lukaskollmer/objc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukaskollmer%2Fobjc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukaskollmer%2Fobjc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukaskollmer%2Fobjc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukaskollmer%2Fobjc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukaskollmer","download_url":"https://codeload.github.com/lukaskollmer/objc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukaskollmer%2Fobjc/sbom","scorecard":{"id":603999,"data":{"date":"2025-08-11","repo":{"name":"github.com/lukaskollmer/objc","commit":"cc4d6f0cb7475b29cdbf16b5662a3b302e36149b"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: license:0","Info: FSF or OSI recognized license: MIT License: license:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"17 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97","Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-76p7-773f-r4q5","Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc","Warn: Project is vulnerable to: GHSA-hc6q-2mpp-qw7j","Warn: Project is vulnerable to: GHSA-4vvj-4cpr-p986","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-21T01:10:06.802Z","repository_id":20096981,"created_at":"2025-08-21T01:10:06.802Z","updated_at":"2025-08-21T01:10:06.802Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29896924,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T12:09:13.686Z","status":"ssl_error","status_checked_at":"2026-02-27T12:09:13.282Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["node-ffi","nodejs","objc","objc-runtime"],"created_at":"2025-03-01T18:28:28.864Z","updated_at":"2026-02-27T13:31:58.248Z","avatar_url":"https://github.com/lukaskollmer.png","language":"JavaScript","readme":"# objc [![Build Status](https://img.shields.io/travis/lukaskollmer/objc.svg?style=flat-square)](https://travis-ci.org/lukaskollmer/objc) [![npm](https://img.shields.io/npm/v/objc.svg?style=flat-square)](https://www.npmjs.com/package/objc) [![node](https://img.shields.io/node/v/objc.svg?style=flat-square)](https://www.npmjs.com/package/objc)\n\n\u003e NodeJS ↔ Objective-C bridge _(experimental)_\n\n\n## Install\n\n```\n$ npm install --save objc\n```\n\n\n## Usage\n\n```js\nconst objc = require('objc');\n\nconst {\n  NSDate,\n  NSDateFormatter\n} = objc;\n\n\nlet now = NSDate.date()\nlet localizedDate = NSDateFormatter.localizedStringFromDate_dateStyle_timeStyle_(now, 2, 2);\n\nconsole.log(localizedDate); // -\u003e \"19. Apr 2017, 22:41:13\"\n\n```\n\n### Topics\n- [API](#api)\n- [Calling Methods](#calling-methods)\n- [Blocks](#blocks)\n- [Constants](#constants)\n- [Structs](#structs)\n- [Inout Parameters](#inout-parameters)\n- [Method Swizzling](#method-swizzling)\n- [Custom Classes](#custom-classes)\n\n### API\n\n##### `objc.import(bundleName)`\nImport an Objective-C framework. Foundation is always imported by default\n\n##### `objc.ns(object, [hint = '@'])`\nConvert a JavaScript object to its objc equivalent. Returns `null` if the object doesn't have an objc counterpart.  \nTakes an optional second parameter to specify whether strings should be converted to `NSString` objects (default), `SEL` or `Class`\n\n##### `objc.js(object, [returnInputIfUnableToConvert = false])`\nConvert an objc object to its JavaScript equivalent.  \nTakes an optional second parameter to specify whether it should return `null` or the input if the object doesn't have a JS counterpart\n\n### Calling methods\nWhen calling Objective-C methods, all you need to do is replace the colons in the selector with underscores.\n\nFor example, this Objective-C code:\n\n```objc\n#import \u003cAppKit/AppKit.h\u003e\n\nNSPasteboard *pasteboard = [NSPasteboard generalPasteboard];\n[pasteboard declareTypes:@[NSPasteboardTypeString] owner:nil];\n\n[pasteboard setString:@\"44 \u003e 45\" forType:NSPasteboardTypeString];\n```\n\nis equivalent to the following JavaScript code:\n\n```js\nconst objc = require('objc');\nobjc.import('AppKit');\n\nconst {NSPasteboard, NSPasteboardTypeString} = objc;\n\nconst pasteboard = NSPasteboard.generalPasteboard();\npasteboard.declareTypes_owner_([NSPasteboardTypeString], null);\n\npasteboard.setString_forType_(\"44 \u003e 45\", NSPasteboardTypeString);\n```\n\n### Blocks\nYou can create a block with the `objc.Block` helper class:\n```js\nconst block = new objc.Block(() =\u003e {\n  console.log('In the block!');\n}, 'v', []);\n```\n\nWhen creating a block, you need to explicitly declare the type encoding of the block's return value and all its parameters.\n\n**Note**  \nIf a block takes an Objective-C object as its parameter, you'll need to manually wrap that object in an `objc.Proxy` (via the `objc.wrap` helper function).\n\n\u003cbr\u003e\n\n**Example:** Sort an array by word length, longest to shortest\n```js\nconst {NSArray, Block, wrap} = objc;\nconst {id, NSInteger} = objc.types;\nconst array = NSArray.arrayWithArray_(['I', 'Am', 'The', 'Doctor']);\n\nconst block = new Block((arg1, arg2) =\u003e {\n  arg1 = wrap(arg1);\n  arg2 = wrap(arg2);\n  return arg1.length() \u003e arg2.length() ? -1 : 1;\n}, NSInteger, [id, id]);  // Match the NSComparator signature\n\nconst sorted = array.sortedArrayUsingComparator_(block);\n// =\u003e ['Doctor', 'The', 'Am', 'I']\n```\n\n### Constants\nYou can load `NSString*` constants just like you'd access a class:\n\n```js\nconst {NSFontAttributeName} = objc;\nconsole.log(NSFontAttributeName);   // =\u003e 'NSFont'\n```\n\n`NSString*` constants are returned as native JavaScript `String` objects.\n\n\n### Structs\nUse the `objc.defineStruct` function to define a struct by its name and layout. The returned type can be used to create instances of the struct, and when specifying type encodings in the `objc` module. It is also compatible with the `ffi-napi`, `ref-napi`, `ref-struct-di` modules.\n\nYou can use the `StructType.new` function to create an instance of the struct. Optionally, you can pass \n\nThe `objc` module already provides a definition for `NSRange`, accessible via `objc.types`.\n\n**Example 1** Using structs with objc methods\n```js\nconst {NSRange} = objc.types;\n\nconst string = objc.ns('Hello World');\nconst substring = string.substringWithRange_(NSRange.new(0, 5));\n// -\u003e 'Hello'\n```\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eExample 2**\u003c/strong\u003e Using structs with the ffi module\u003c/summary\u003e\n\n```js\nconst ffi = require('ffi-napi');\nconst CGFloat = objc.types.double;\n\nconst CGPoint = objc.defineStruct('CGPoint', {\n  x: CGFloat,\n  y: CGFloat\n});\n\nconst CGSize = objc.defineStruct('CGSize', {\n  width: CGFloat,\n  height: CGFloat\n});\n\nconst CGRect = objc.defineStruct('CGRect', {\n  origin: CGPoint,\n  size: CGSize\n});\n\nconst libFoundation = new ffi.Library(null, {\n  NSStringFromRect: ['pointer', [CGRect]]\n});\nconst rect = CGRect.new(\n  CGPoint.new(5, 10),\n  CGSize.new(100, 250)\n);\nconst string = objc.wrap(libFoundation.NSStringFromRect(rect))\n// -\u003e '{{5, 10}, {100, 250}}'\n```\n\u003c/details\u003e\n\n\n### Inout parameters\nIf a method expects an inout parameter (like `NSError**`), you can use the `objc.allocRef` function to get a pointer to a `nil` objc object that can be passed to a method expecting an `id*`:\n```js\nconst {NSAppleScript} = objc;\n\nconst script = NSAppleScript.alloc().initWithSource_('foobar');\n\nconst error = objc.allocRef();\nscript.executeAndReturnError_(error); // `executeAndReturnError:` takes a `NSDictionary**`\n\nconsole.log(error); // `error` is now a `NSDictionary*`\n```\nOutput:\n```\n[objc.InstanceProxy {\n    NSAppleScriptErrorBriefMessage = \"The variable foobar is not defined.\";\n    NSAppleScriptErrorMessage = \"The variable foobar is not defined.\";\n    NSAppleScriptErrorNumber = \"-2753\";\n    NSAppleScriptErrorRange = \"NSRange: {0, 6}\";\n}]\n```\nIf you need more advanced inout functionality (using primitive types, etc), simply use the [`ref`](https://github.com/TooTallNate/ref) module.\n\n\n### Method swizzling\nMethod swizzling allows you to replace a method's implementation:\n```js\nconst {NSProcessInfo} = objc;\nobjc.swizzle(NSProcessInfo, 'processorCount', (self, _cmd) =\u003e {\n  return 12;\n});\n\nNSProcessInfo.processInfo().processorCount(); // =\u003e 12\n```\n\nThe method's original implementation is still available, with the `xxx__` prefix:\n\n```js\nconst {NSDate, wrap} = objc;\nobjc.swizzle(NSDate, 'dateByAddingTimeInterval:', (self, _cmd, timeInterval) =\u003e {\n  self = wrap(self);\n  return self.xxx__dateByAddingTimeInterval_(timeInterval * 2);\n});\n\nconst now = NSDate.date();\nconst a = now.dateByAddingTimeInterval_(2);\nconst b = now.xxx__dateByAddingTimeInterval_(4);\n\na.isEqualToDate_(b); // =\u003e true\n```\n**Note**\n- Just like with blocks, you have to `wrap` all non-primitive parameters\n- If you want to swizzle a class method, pass `'class'` as the `swizzle` function's last parameter\n- `objc.swizzle` returns a function that - if called - restores the original implementation of the swizzled method\n\n### Custom Classes\nUse the `objc.createClass` function to register custom classes with the Objective-C runtime:\n```js\nconst objc = require('objc');\n\nconst LKGreeter = objc.createClass('LKGreeter', 'NSObject', {\n  'greet:': (self, cmd, name) =\u003e {\n    name = objc.wrap(name);\n    return objc.ns(`Hello, ${name}!`);\n  },\n\n  _encodings: {\n    'greet:': ['@', ['@', ':', '@']]\n  }\n});\n\nLKGreeter.new().greet('Lukas'); // =\u003e 'Hello, Lukas!'\n```\n**Note**: You might have to specify individual offsets in the type encoding, see [this example](/examples/delegate.js).\n\n## Roadmap\nIn the future, I'd like to add support for:\n- improved support for inout parameters (`id*`)\n- c-style arrays, unions as method parameter/return type\n- runtime introspection (accessing an object's properties, ivars, methods, etc)\n- improved class creation api\n\n## License\nMIT © [Lukas Kollmer](https://lukaskollmer.me)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukaskollmer%2Fobjc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukaskollmer%2Fobjc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukaskollmer%2Fobjc/lists"}