[英]Incomplete definition of type “struct objc_method”
我真的很困惑這個問題。 我需要做的是在我的項目中使用一些obj-c運行時功能。 這是我的.m文件中的簡單代碼:
#import "Base.h"
#import <objc/runtime.h>
@implementation Base
- (void)someMethod {
NSUInteger numberMethods = 0;
Method *classMethods = class_copyMethodList([self class], &numberMethods);
for (int i = 0; i < numberMethods; i ++) {
classMethods[i]->method_name; //incomplete definition of type "struct objc_method"
}
@end
我收到以下錯誤:類型“struct objc_method”的定義不完整。 在檢查了objc / runtime.h文件后,我發現了這樣的事情:
一些代碼......
typedef struct objc_method *Method;
......一些代碼......
struct objc_method {
SEL method_name OBJC2_UNAVAILABLE;
char *method_types OBJC2_UNAVAILABLE;
IMP method_imp OBJC2_UNAVAILABLE;
}
這類似於前向聲明問題還是別的什么?
除了Martin回答之外,你應該使用method_getName
類的method_getName
來檢索方法classMethods[i]
。
這更容易移植(特別是結構中的這些字段不再存在,因為宏建議使用Objective-C 2.0)並且可以避免像Runtime演變時那樣的問題。
這些成員無法訪問! OBJC2_UNAVAILABLE宏表示成員不可用,只提供對結構的一些了解。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.