do I need to add/modify anything here re memory management for a custom class? (e.g. any “release” lines required, don’t need a dealloc method?)
#import <Foundation/Foundation.h>
@interface TimelineItem : NSObject {
NSDate *_startDate;
BOOL _working;
BOOL _coreWeekend;
}
@property (nonatomic, retain) NSDate *startDate;
@property (nonatomic) BOOL working;
@property (nonatomic) BOOL coreWeekend;
- (id)initWithStartDate:(NSDate*)startDate Working:(BOOL)working CoreWeekend:(BOOL)coreWeekend;
@end
#import "TimelineItem.h"
@implementation TimelineItem
@synthesize startDate = _startDate;
@synthesize working = _working;
@synthesize coreWeekend = _coreWeekend;
- (id)initWithStartDate:(NSDate*)startDate Working:(BOOL)working CoreWeekend:(BOOL)coreWeekend {
if (self == [super init])
{
// Initialization
self.startDate = startDate;
self.working = working;
self.coreWeekend = coreWeekend;
}
return self;
}
@end
No, it is not. You’ve
retainedthestartDateparameter by declaring your property as(retain). This means you’re responsible forreleasingit at some point. You can fix this by adding:Also, you shouldn’t be capitalizing “Working” and “CoreWeekend” in the init method name. They should be “working” and “coreWeekend”, respectively.