
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
cocoascript-class
Advanced tools
Lets you create real ObjC classes in cocoascript so you can implement delegates, subclass builtin types, etc
Lets you create real ObjC classes in cocoascript so you can implement delegates, subclass builtin types, etc
In your plugin, assuming you're already using an ES6 build toolchain and either npm
or yarn
npm install --save cocoascript-class
or yarn add cocoascript-class
Here is an example class created with this:
const MyClass = new ObjCClass({
// String values create ivar
_private: 'initial',
// This is a method on the class.
test() {
log("test: " + this._private);
},
});
// MyClass is now a real ObjC class as far as cocoascript is concerned:
const obj = MyClass.new();
// You can use setters for the ivars
obj._private = "efgh";
// And call methods
[obj test];
obj.test();
The 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.
SuperCall(sel, argumentTypes, returnType);
each argument or return type is just an object with {type: encodedString}
, where encodedString is the Objective-C type encoding of that type, for example:
@encode(char*) = "*"
@encode(id) = "@" // any object can use this encoding
@encode(Class) = "#"
@encode(void*) = "^v"
@encode(CGRect) = "{CGRect={CGPoint=dd}{CGSize=dd}}"
@encode(SEL) = ":"
Here, we call [super description]
in our class' description method:
import ObjCClass, {SuperCall} from 'cocoascript-class';
const HasDescriptionClass = new ObjCClass({
description() {
// You should cache the result of SuperCall function, don't look it up each time
if (typeof MyClass._superDesc == 'undefined') {
const sel = NSStringFromSelector('description');
MyClass._superDesc = SuperCall(sel, [], {type:"@"});
}
const superDesc = MyClass._superDesc.call(this);
return NSString.stringWithString(`${superDesc} { _private=${this._private} }`);
}
});
// MyClass is now a real ObjC class as far as cocoascript is concerned:
const obj = HasDescriptionClass.new();
log(obj); // calls description to become a string
FAQs
Lets you create real ObjC classes in cocoascript so you can implement delegates, subclass builtin types, etc
The npm package cocoascript-class receives a total of 503 weekly downloads. As such, cocoascript-class popularity was classified as not popular.
We found that cocoascript-class demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.