Problem
I am trying to create an object in Objective-C. I know how to do it but I have a few questions regarding the methods in the implementation file.
The Object:
@interface Program : NSObject {
NSString *sid;
NSString *le;
NSString *sd;
NSString *pid;
NSString *n;
NSString *d;
NSString *url;
}
@property (nonatomic, retain) NSString *sid;
@property (nonatomic, retain) NSString *le;
@property (nonatomic, retain) NSString *sd;
@property (nonatomic, retain) NSString *pid;
@property (nonatomic, retain) NSString *n;
@property (nonatomic, retain) NSString *d;
@property (nonatomic, retain) NSString *url;
@end
Question
I should only implement dealloc and init.. Am I right on this?
Furthermore, I have no special initializations, so should I keep the default init method as follows?
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
You need to synthesize the properties and if you don’t need any custom initialization then you can keep the
initmethod as it is. In fact there is no need to implementinithere. But indeallocyou need to release the strings.