It should be possible to replace the implementation of existing Objective-C classes with method swizzling.
Here's an example of swizzling class methods:
var nativeStaticMethod = TNSSwizzleKlass.staticMethod;
TNSSwizzleKlass.staticMethod = function (x) {
return 2 * nativeStaticMethod.apply(this, arguments);
};
And the native class method should be replaced by the javascript implementation.
Another example with instance methods:
var nativeInstanceMethod = TNSSwizzleKlass.prototype.instanceMethod;
TNSSwizzleKlass.prototype.instanceMethod = function (x) {
return 2 * nativeInstanceMethod.apply(this, arguments);
};
And with instance properties:
var nativeProperty = Object.getOwnPropertyDescriptor(TNSSwizzleKlass.prototype, "aProperty");
Object.defineProperty(TNSSwizzleKlass.prototype, 'aProperty', {
get: function () {
return 2 * nativeProperty.get.call(this);
},
set: function (x) {
nativeProperty.set.call(this, 2 * x);
}
});
It should be possible to replace the implementation of existing Objective-C classes with method swizzling.
Here's an example of swizzling class methods:
And the native class method should be replaced by the javascript implementation.
Another example with instance methods:
And with instance properties: