Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.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
Objective c AppDelegate';s的属性不可访问_Objective C - Fatal编程技术网

Objective c AppDelegate';s的属性不可访问

Objective c AppDelegate';s的属性不可访问,objective-c,Objective C,我在AppDelegate.m接口中创建了一个属性countrynamesinitials作为NSMutableArray,并将其合成。其目的是存储要在表视图中显示的全局数据。在“表视图”控制器中: #import "AppDelegate.h" ... @implementation #define AppDelegate [[UIApplication sharedApplication] delegate] ... 问题是我无法使用AppDelegate.countrynamesini

我在AppDelegate.m接口中创建了一个属性
countrynamesinitials
作为NSMutableArray,并将其合成。其目的是存储要在表视图中显示的全局数据。在“表视图”控制器中:

#import "AppDelegate.h"
...

@implementation
#define AppDelegate [[UIApplication sharedApplication] delegate]
...
问题是我无法使用
AppDelegate.countrynamesinitials
访问数据。有什么想法吗

事实是

 [[UIApplication sharedApplication] delegate]
将为您提供一个通用的
UIApplcationLegate
;虽然您需要您的
MyOwnAppDelegate
(不知道如何称呼它)类型才能使用您的
countrynamesinitials
属性。因此,请尝试:

 #define AppDelegate ((MyOwnAppDelegate*)[[UIApplication sharedApplication] delegate])
然后

应该有用


(不过,我不会对类和宏使用相同的名称)。

访问
countrynamesinitials
的问题是由于我在AppDelegate.m中声明了属性。在我将其移动到AppDelegate.h之后,错误就消失了

旁注:
1.
AppDelegate
,因为标识符名称对我有效。@Vakio建议的命名冲突不相关。

这可能是命名冲突。您的#define与AppDelegate类具有相同的名称。试着把你的#define换成另一个名字。好主意。但是我尝试了其他名称,仍然无法复制粘贴您的#define行,但在message send expression的开头出现了一个错误“missing'[”您可以将出现错误的行粘贴到哪里吗?该语法对我来说适用于属性取消引用…
#define AppDelegate((TableWithInxingAppDelegate*)[[UIApplication sharedApplication]委托]
我觉得奇怪的是,
#define
本身会产生错误…我可以将它粘贴到我的任何项目中,它会编译。。。
AppDelegate.countryNameInitials