例如,有一个Person类,他有一本书,Book类,它有一个拥有者。。。
#import
#import “Book.h”
@interface Person : NSObject
@property(nonatomic,strong)Book *book;
@end
#import “Person.h”
@implementation Person
– (void)dealloc
{
NSLog(@“人挂了。。。”);
}
@end
#import
@class Person;
//两个类互相引用,必须有1方是用@class关键字,如果两边都是#import,就会造成循环引用,无限循环。。。
@interface Book : NSObject
@property(nonatomic,strong)Person *owner;
//OC对象,用strong
@end
#import “Book.h”
#import “Person.h”
//Book.h文件用@class Person;了,所以Book.m文件再引用一下Person.h,不会报错,还能有提示
@implementation Book
– (void)dealloc
{
NSLog(@“书被烧毁了。。。”);
}
@end
#imp