Too late to ask about class initialization

Discussion in 'iOS Programming' started by mikezang, Nov 30, 2010.

  1. mikezang, Nov 30, 2010
    Last edited: Nov 30, 2010

    mikezang macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #1
    I thought I understand this topic, but now I got confuse. I have some classes as below, I am not sure if I have to provide a init method, I want to know when I have to have a init when not:
    Code:
    @interface MarketEvent : NSObject {
        int day;
        NSString *title;
    }
    
    @property (nonatomic, assin) int day;
    @property (nonatomic, retain) title;
    @end
    
    @inplementation MarketEvent
    @synthesize year;
    @synthesize title;
    
    -(void)dealloc {
        [title release];
        [super dealloc];
    }
    @end
    
    Code:
    @interface MrketEvents : NSObject {
        NSArray *events;
    }
    
    @property (nonatomic, retain) NSArray *events;
    @end
    
    @inplementation MarketEvents
    @synthesize events;
    
    -(void)dealloc {
        [events release];
        [super dealloc];
    }
    @end
    
     
  2. Comrade Yeti macrumors newbie

    Joined:
    Nov 3, 2010
    #2
    You need an init whenever you want any member variables initialized to anything other than 0 or nil.
     

Share This Page