Utilisez le code class_addMethod
:runtime - Que signifie "@@:" dans class_addMethod?
class_addMethod(newClass, @selector(inputAccessoryView), accessoryImp, "@@:");
Quelle dose le paramètre "@@:" signifie dans cette méthode?
Doc:
/**
* Adds a new method to a class with a given name and implementation.
*
* @param cls The class to which to add a method.
* @param name A selector that specifies the name of the method being added.
* @param imp A function which is the implementation of the new method. The function must take at least two arguments—self and _cmd.
* @param types An array of characters that describe the types of the arguments to the method.
*
* @return YES if the method was added successfully, otherwise NO
* (for example, the class already contains a method implementation with that name).
*
* @note class_addMethod will add an override of a superclass's implementation,
* but will not replace an existing implementation in this class.
* To change an existing implementation, use method_setImplementation.
*/
OBJC_EXPORT BOOL class_addMethod(Class cls, SEL name, IMP imp,
const char *types)
OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0);
Si 'SEL' est' @selector (viewWithObject:) ', les' types' seront "@@: @"? – tomfriwel
@tom: Oui si la méthode prend un objet en argument et renvoie un objet. –