{"id":20997891,"url":"https://github.com/darknoon/cocoascript-class","last_synced_at":"2025-05-14T23:30:54.351Z","repository":{"id":51861116,"uuid":"86114984","full_name":"darknoon/cocoascript-class","owner":"darknoon","description":"Lets you create real ObjC classes in cocoascript so you can implement delegates, subclass builtin types, etc","archived":true,"fork":false,"pushed_at":"2023-01-12T06:13:40.000Z","size":82,"stargazers_count":23,"open_issues_count":15,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T14:49:57.956Z","etag":null,"topics":["cocoascript","sketch-plugin"],"latest_commit_sha":null,"homepage":null,"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/darknoon.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}},"created_at":"2017-03-24T22:16:07.000Z","updated_at":"2025-02-06T12:33:48.000Z","dependencies_parsed_at":"2023-02-09T10:30:56.355Z","dependency_job_id":null,"html_url":"https://github.com/darknoon/cocoascript-class","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/darknoon%2Fcocoascript-class","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darknoon%2Fcocoascript-class/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darknoon%2Fcocoascript-class/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darknoon%2Fcocoascript-class/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darknoon","download_url":"https://codeload.github.com/darknoon/cocoascript-class/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254248007,"owners_count":22038943,"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":["cocoascript","sketch-plugin"],"created_at":"2024-11-19T07:42:31.755Z","updated_at":"2025-05-14T23:30:49.323Z","avatar_url":"https://github.com/darknoon.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cocoascript-class\nLets you create real ObjC classes in cocoascript so you can implement delegates, subclass builtin types, etc\n\n## Installation\n\nIn your plugin, assuming you're already using an ES6 build toolchain and either `npm` or `yarn`\n\n`npm install --save cocoascript-class` or `yarn add cocoascript-class`\n\n\n## Usage\n\nHere is an example class created with this:\n\n````js\nconst MyClass = new ObjCClass({\n  // String values create ivar\n  _private: 'initial',\n  \n  // This is a method on the class.\n  test() {\n    log(\"test: \" + this._private);\n  },\n});\n\n// MyClass is now a real ObjC class as far as cocoascript is concerned:\nconst obj = MyClass.new();\n\n// You can use setters for the ivars\nobj._private = \"efgh\";\n\n// And call methods\n[obj test];\nobj.test();\n\n````\n\n## Advanced\n\n\n### Calling super\n\n\nThe `SuperCall` function will let you send a message to your superclass, equivalent to `[super myMethod]`. However, you need to tell it the types of the arguments to your function.\n\n````js\nSuperCall(sel, argumentTypes, returnType);\n````\n\neach argument or return type is just an object with `{type: encodedString}`, where encodedString is the [Objective-C type encoding](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html) of that type, for example:\n\n````\n@encode(char*) = \"*\"\n@encode(id) = \"@\" // any object can use this encoding\n@encode(Class) = \"#\"\n@encode(void*) = \"^v\"\n@encode(CGRect) = \"{CGRect={CGPoint=dd}{CGSize=dd}}\"\n@encode(SEL) = \":\"\n````\n\nHere, we call `[super description]` in our class' description method:\n\n````js\n\nimport ObjCClass, {SuperCall} from 'cocoascript-class';\n\nconst HasDescriptionClass = new ObjCClass({  \n  description() {\n    // You should cache the result of SuperCall function, don't look it up each time\n    if (typeof MyClass._superDesc == 'undefined') {\n      const sel = NSStringFromSelector('description');\n      MyClass._superDesc = SuperCall(sel, [], {type:\"@\"});\n    }\n    const superDesc = MyClass._superDesc.call(this);\n    return NSString.stringWithString(`${superDesc} { _private=${this._private} }`);\n  }\n});\n\n// MyClass is now a real ObjC class as far as cocoascript is concerned:\nconst obj = HasDescriptionClass.new();\nlog(obj); // calls description to become a string\n````\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarknoon%2Fcocoascript-class","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarknoon%2Fcocoascript-class","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarknoon%2Fcocoascript-class/lists"}