bạn có thể làm điều này và nó cực kỳ cũng là tài liệu tại https://developer.apple.com/library/mac/documentation/cocoa/Reference/ObjCRuntimeRef/index.html
Để lấy tất cả các ví dụ hoặc lớp method của một class, bạn có thể sử dụng class_copyMethodList
vấn và duyệt qua các kết quả. Ví dụ:
#import <objc/runtime.h>
/**
* Gets a list of all methods on a class (or metaclass)
* and dumps some properties of each
*
* @param clz the class or metaclass to investigate
*/
void DumpObjcMethods(Class clz) {
unsigned int methodCount = 0;
Method *methods = class_copyMethodList(clz, &methodCount);
printf("Found %d methods on '%s'\n", methodCount, class_getName(clz));
for (unsigned int i = 0; i < methodCount; i++) {
Method method = methods[i];
printf("\t'%s' has method named '%s' of encoding '%s'\n",
class_getName(clz),
sel_getName(method_getName(method)),
method_getTypeEncoding(method));
/**
* Or do whatever you need here...
*/
}
free(methods);
}
Bạn cần thực hiện hai cuộc gọi riêng biệt cho phương thức này. Một cho các phương pháp dụ và một cho các phương thức lớp:
/**
* This will dump all the instance methods
*/
DumpObjcMethods(yourClass);
Calling cùng trên metaclass sẽ cung cấp cho bạn tất cả các phương thức lớp
/**
* Calling the same on the metaclass gives you
* the class methods
*/
DumpObjcMethods(object_getClass(yourClass) /* Metaclass */);
liên kết này bây giờ chuyển hướng đến trang chuyển hướng – user3125367
Táo docs đã nhận kinh khủng hơn. Câu trả lời của Buzzy dưới đây là một câu trả lời tốt hơn nhiều. – Paul