NodObjC

The NodeJS ⇆ Objective-C Bridge

blockbridgesupportclasscoreexceptionffi-extendglobalidimpimportindexivarmethodselstructtypes

Method

Represents an Objective-C "Method" instance. These do not respond to regular messages, so it does not inherit from id.

wrap()

This is a private function used internally by NodObjC. You should not need to use this function in your code.

Returns a new Method instance wrapping the given pointer.

function wrap (pointer) {
  if (pointer.isNull()) {
    return null
  }
  return new Method(pointer)
}

Method()

This is a private function used internally by NodObjC. You should not need to use this function in your code.

Method wrapper class constructor.

function Method (pointer) {
  this.pointer = pointer
}

Method#getArgumentType()

Returns the "argument type" string, for the given argument index.

proto.getArgumentType = function getArgumentType (index) {
  var ptr = core.method_copyArgumentType(this.pointer, index)
    , str = core.getStringAndFree(ptr)
  return str
}

Method#getArgumentTypes()

Returns an Array of all "argument types" for this method.

proto.getArgumentTypes = function getArgumentTypes () {
  var rtn = []
    , len = this.getNumberOfArguments()
  for (var i=0; i<len; i++) {
    rtn.push(this.getArgumentType(i))
  }
  return rtn
}

Method#getReturnType()

Returns the "type encoding" of the method's return value.

proto.getReturnType = function getReturnType () {
  var ptr = core.method_copyReturnType(this.pointer)
    , str = core.getStringAndFree(ptr)
  return str
}

Method#getTypes()

Returns an Array of "type encodings". The array has a length of 2. The first element is the method return type. The second element is an Array of all the method's argument types.

proto.getTypes = function getTypes () {
  return [ this.getReturnType(), this.getArgumentTypes() ]
}

Method#exchangeImplementations()

Exchanges the method's implementation function with another Method instance. This is the preferred way to "swizzle" methods in Objective-C.

proto.exchangeImplementations = function exchangeImplementations (other) {
  return core.method_exchangeImplementations(this.pointer, other.pointer)
}

Method#getImplementation()

Returns the function implementation of this Method. Also known as the IMP of the method. The returned object is a regular JavaScript Function which may be invoked directly, when given valid "self" and "_sel" arguments.

proto.getImplementation = function getImplementation () {
  return IMP.createUnwrapperFunction(core.method_getImplementation(this.pointer), this.getTypes())
}

Method#getName()

Returns the name of this Method.

proto.getName = function getName () {
  return SEL.toString(core.method_getName(this.pointer))
}

Method#getNumberOfArguments()

Returns the number of defined arguments this Method accepts.

proto.getNumberOfArguments = function getNumberOfArguments () {
  return core.method_getNumberOfArguments(this.pointer)
}

Method#getTypeEncoding()

Returns the overall "type encoding" of this Method. This is a compacted/stringified version of getTypes(), so usually you will use that over this function.

proto.getTypeEncoding = function getTypeEncoding () {
  return core.method_getTypeEncoding(this.pointer)
}

Method#setImplementation()

Set's this Method's implementation function. The IMP function may be a regular JavaScript function or another function IMP retreived from a previous call to Method#getImplementation().

proto.setImplementation = function setImplementation (func) {
  var types = this.getTypes()
    , wrapperPtr = IMP.createWrapperPointer(func, types)
    , oldFuncPointer = core.method_setImplementation(this.pointer, wrapperPtr)
  return IMP.createUnwrapperFunction(oldFuncPointer, types)
}
Fork me on GitHub