Skip to content

Instantly share code, notes, and snippets.

@oleavr
Created June 3, 2015 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oleavr/8c24293c53f9ea8c07bd to your computer and use it in GitHub Desktop.
Save oleavr/8c24293c53f9ea8c07bd to your computer and use it in GitHub Desktop.
ObjC class creation API draft 2
const NSAutoreleasePool = ObjC.classes.NSAutoreleasePool;
const pool = NSAutoreleasePool.alloc().init();
const NSObject = ObjC.classes.NSObject;
const NSURLConnectionDataDelegate = ObjC.protocols.NSURLConnectionDataDelegate;
const MyConnectionDelegateProxy = ObjC.registerClass({
name: 'MyConnectionDelegateProxy',
parent: NSObject,
protocols: [NSURLConnectionDataDelegate],
overrides: {
'- init': function () {
const self = this.super.init();
if (self !== null) {
ObjC.bind(self, {
foo: 1234
});
}
return self;
},
'- dealloc': function () {
ObjC.unbind(this.self);
this.super.dealloc();
},
'- connection:didReceiveResponse:': function (connection, response) {
/* this.data contains `foo` with a value of 1234 */
}
}
});
const proxy = MyConnectionDelegateProxy.alloc().init();
pool.release();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment