2011-04-30 81 views
0

我的Xcode 4只死机了,我得到编译错误:Xcode4崩溃会使应用程序构建失败

未知类型名称 'SecondViewController'

在@interface代码块

SecondViewController *sms; 

and

属性与 '保留' 属性必须 是对象类型

@property(nonatomic,retain) SecondViewController *sms; 

但是我导入SecondViewController.h。相同的代码在崩溃之前工作。

FirstViewController.h:http://pastebin.com/jnPKBny7

SecondViewController.h:http://pastebin.com/2D058ZAK

编辑:我意识到这个错误occures因为这些类导入对方。任何人都可以描述为什么这是错的?

有什么建议吗?

+0

你能后的SecondViewController头文件和文件你在哪里得到这些错误? – drewag 2011-04-30 16:10:00

+0

我编辑了我的问题 – 2011-04-30 16:56:00

+1

SecondViewController.m是否显示在项目导航器 - >第一项/您的项目 - >右窗口目标 - >构建阶段 - >编译源? – 2011-04-30 17:34:00

回答

1

您不能有循环导入。我认为尽可能使用带有@class指令的前向类声明是一种很好的做法。对于您的情况:

FirstViewController.h:

@class SecondViewController ; 
@interface FirstViewController 
{ 
    SecondViewController * _secondViewController ; 
} 

@property (nonatomic, retain) secondViewControlller ; 

@end 

SecondViewController.h:

@class FirstViewController ; 
@interface SecondViewController 
{ 
    FirstViewController * _firstViewController ; 
} 

@property (nonatomic, retain) firstViewControlller ; 

@end 

然后在你的.m文件,输入您所使用的类的.h文件。以文件导入.H到其他.h文件的唯一原因是:

  • 框架进口(即)
  • 你需要使用的协议