在类型“y *”的对象上找不到属性“x”,只有ARC [英] Property 'x' not found on object of type 'y *' error only with ARC
问题描述
这个错误很奇怪。我有一大堆属性在应用程序委托,我没有问题,访问。我的代码工作正常没有ARC,但当我打开ARC我收到这个非常奇怪的错误。
在'AppDelegate *'类型的对象上没有找到属性'navigationController'
This error very strange. I have a bunch of properties in app delegate which I have no problem to access. My code worked fine without ARC, but when I turned on ARC I receive this very strange error. Property 'navigationController' not found on object of type 'AppDelegate *'
除此之外,一系列其他属性都很好。
A bunch of other properties work just fine except this.
我已经清理所有内容并重新启动Xcode。
I already clean everything and restarted Xcode.
这是代码:
AppDelegate.h:
AppDelegate.h:
@interface AppDelegate : UIResponder <UINavigationControllerDelegate> {
UINavigationController *navigationController;
NSString *appName;
}
@property (strong, nonatomic) NSString *appName;
@property (strong, nonatomic) UINavigationController *navigationController;
AppDelegate.m
AppDelegate.m
#import "AppDelegate.h"
@synthesize navigationController, appName;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
appName = [NSString stringWithString:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]];
navigationController = [[UINavigationController alloc] initWithRootViewController:self.startViewController];
}
MyClass.h
MyClass.h
@class AppDelegate;
@interface MyClass: UIResponder {
AppDelegate *appDelegate;
}
MyClass.m
MyClass.m
#import "AppDelegate.h"
#import "MyClass.h"
@implementation MyClass
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[self initFacebook];
}
return self;
}
- (void) doStuff {
NSLog(@"App Name:%@",appDelegate.appName); //this works fine
//This one doesn't
UINavigationController *myNavigationController = appDelegate.navigationController;
}
更新:
我做了一个解决方法。基本上,我在MyClass中创建了一个名为navigationViewController的属性,我在AppDelegate中实例化MyClass之后传递对象,而不是直接从MyCLass中的AppDelegate获取(如上所示)。我还是困惑,它一定是编译器中的一个错误。我仍然非常感兴趣如何使原始代码工作。
Update: I did a workaround. Basically I created a property in MyClass called navigationViewController and I pass the object after MyClass is instantiated in AppDelegate instead of getting directly from AppDelegate in MyCLass (as shown above). I'm still puzzled, it must be a bug in the compiler. I'm still very interested in how to make the original code work.
推荐答案
在MyClass.m,导入MyClass而不是MyClass.h。
有时清理项目是不够的:您可能需要打开管理器窗口,在项目选项卡下选择您的项目,并单击按钮以删除衍生数据。
Sometimes cleaning a project is not sufficient: you may need to open the Organizer window, select your project under the Projects tab, and click the button to delete Derived Data.
这篇关于在类型“y *”的对象上找不到属性“x”,只有ARC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!