Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么两个id变量的类\u copyPropertyList()存在差异,但具有相同的类类型 id appdel=[[UIApplication sharedApplication]委托];//_Ios_Iphone - Fatal编程技术网

Ios 为什么两个id变量的类\u copyPropertyList()存在差异,但具有相同的类类型 id appdel=[[UIApplication sharedApplication]委托];//

Ios 为什么两个id变量的类\u copyPropertyList()存在差异,但具有相同的类类型 id appdel=[[UIApplication sharedApplication]委托];//,ios,iphone,Ios,Iphone,这两个论点是不同的 id casualcore_app_delegate = objc_getClass("MyAppDelegate"); unsigned int outCount, i; // <--- outCount will be the correct property count objc_property_t *properties = class_copyPropertyList(casualcore_app_delegate, &outCount); f

这两个论点是不同的

id casualcore_app_delegate = objc_getClass("MyAppDelegate");

unsigned int outCount, i;  // <--- outCount will be the correct property count
objc_property_t *properties = class_copyPropertyList(casualcore_app_delegate, &outCount);

for (i = 0; i < outCount; i++)
{
  objc_property_t property = properties[i];
  fprintf(stdout, "%s %s\n", property_getName(property), property_getAttributes(property));
}
是MyAppDelegate类的实例,并且

id appdel = [[UIApplication sharedApplication] delegate];
这就是课堂本身

现在,
class\u copyPropertyList()
的第一个参数是一个类,因此它可以工作 在第二个例子中,但不是在第一个例子中。如果你改变

id casualcore_app_delegate = objc_getClass("MyAppDelegate");


然后,您的第一个示例也会起作用,并给出相同的结果。

将您的第一个示例更新为:

objc_property_t * property_list = class_copyPropertyList([appdel class], &property_count);

然后它将与第二个示例相同。

在Obj-C中,每个类也是一个对象。objc_getClass(“MyAppDelegate”)返回类对象,而不是该类的实例。此外,
id
不是一种变量类型。它只是一个指向RAM芯片中任意位置的整数。它可以指向任何东西。当您希望编译器警告您这里所犯的错误时,不要使用
id
objc_property_t * property_list = class_copyPropertyList(appdel, &property_count);
objc_property_t * property_list = class_copyPropertyList([appdel class], &property_count);
id appdel = [[[UIApplication sharedApplication] delegate] class];