Created
June 3, 2015 19:41
-
-
Save oleavr/8c24293c53f9ea8c07bd to your computer and use it in GitHub Desktop.
ObjC class creation API draft 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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