my xcode 4 just crashed and I get build errors:
Unknown type name 'SecondViewController'
in the @interface code block:
SecondViewController *sms;
and
Property with 'retain' attribute must be object type
in
@property(nonatomic,retain) SecondViewController *sms;
开发者_StackOverflow中文版
However I import SecondViewController.h. The same code worked before the crash.
FirstViewController.h: http://pastebin.com/jnPKBny7
SecondViewController.h: http://pastebin.com/2D058ZAK
Edit: I realized that this error occures because the classes import each other. Can anyone describe why this is wrong?
Any ideas?
You can't have circular imports. I think it's good practice to use forward class declarations with the @class directive whenever possible. For your case:
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
Then in your .m files, import the .h files for the classes you are using. The only reasons to import .h files into other .h files are:
- framework imports (i.e. )
- you need to use a protocol
精彩评论