@interface Book : NSObject @property (nonatomic) NSString *title; @property (nonatomic) NSString *author; @property (nonatomic) int yearOfPublication; -(instancetype)initWithTitle:(NSString*)title author:(NSString*)author year:(init)year; @end // Book.m @implementation Book -(instancetype)initWithTitle:(NSString*)title author:(NSString*)author year:(int)year { self = [super init]; if(self){ _title = title; _author = author; _yearOfPublication = year; } return self; } @end
Weak references for:
1. delegates
2. subviews of the main view
Person.h
@interface Person : NSObject @property (nonatomic) NSString *name; @property (nonatomic) NSDate *birthday; @end
Person.m
// Person.m @implementation Person -(instancetype)initWithName:(NSString*)name birthday:(NSDate*)birthday { self = [super init]; if(self){ _name = name; _birthday = birthday; } return self; } @end
Book.h
#import "Person.h" @interface Book : NSObject @property (nonatomic) NSString *title; @property (nonatomic) Person *author; @property (nonatomic) int yearOfPublication; -(instancetype)initWithTitle:(NSString*)title author:(Person*)author year:(int)year; @end