title: addObjects adds only last object to NSMutableArray
body: <p>I am making an Schedule class and trying to output all events in a loop in a ViewController. I have created an Event class and Schedule class. I am looping thorough NSMutableArray to get the text all of all the events. My problem is that when I am in the <strong>addNewEvent</strong> method in Schedule.m file I overwrite my NSMutable array with the last object I am adding through <strong>addObject</strong>. My goal is to add all the event objects one by one into the array and display their text. It would also be nice if I could set separate IDs for the event objects. I understand that I probably need to loop through something in the <strong>addNewEvent</strong> method when I am adding objects to the mutable array, but I don't know through what. I also thought that maybe I am initializing the NSMutableArray (which is a property of the Schedule class) in the wrong place, but it gives an error if I move the initializer anywhere else.</p>
  
  <p>Could you please help me solve this problem. Any help will be much appreciated!</p>
  
  <p>My Code is below. I have two classes (Event &amp; Schedule) and a ViewController file.</p>
  
  <p>Event.h:</p>
  
  <pre><code>@interface Event : NSObject
  
  @property int eventId;
  
  @property NSString * eventTitle;
  
  @property NSString * eventDescription;
  
  @property NSDate * eventDate;
  
  -(void) logEvent;
  
  -(NSString*) getEventText;
  
  @end
  </code></pre>
  
  <p>Event.m:</p>
  
  <pre><code>#import "Event.h"
  
  @implementation Event
  
  -(NSString*) getEventText {
  
      NSString * eventText1 = [NSString stringWithFormat: @"\n\nEvent ID: %d.\n", _eventId];
  
      NSString * eventText2 = [eventText1 stringByAppendingFormat: @"Title: %@.\n", _eventTitle];
  
      NSString * eventText3 = [eventText2 stringByAppendingFormat:@"Description: %@.\n", _eventDescription];
  
      NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
      dateFormatter.dateStyle = NSDateFormatterFullStyle;
      dateFormatter.timeStyle = NSDateFormatterShortStyle;
  
      NSString * eventText = [eventText3 stringByAppendingFormat:@"Date: %@.\n\n", [dateFormatter stringFromDate:_eventDate]];
  
      return eventText;
  }
  
  @end
  </code></pre>
  
  <p>Schedule.h:</p>
  
  <pre><code>@interface Schedule : NSObject
  
  @property int idIndex;
  
  @property NSMutableArray * scheduledEvents;
  
  -(NSString*) getAllEventText;
  
  -(void)addNewEventWithTitle:(NSString *)Title Description:(NSString *)Description andDate:(NSDate *)Date;
  
  @end
  </code></pre>
  
  <p>Schedule.m:</p>
  
  <pre><code>#import "Schedule.h"
  #import "Event.h"
  
  @implementation Schedule
  
  -(void)addNewEventWithTitle:(NSString *)Title Description:(NSString *)Description andDate:(NSDate *)Date {
  
      Event * event = [[Event alloc] init];
  
      _idIndex = 1;
  
      [event setEventTitle:Title];
      [event setEventDescription:Description];
      [event setEventDate:Date];
      [event setEventId:_idIndex];
  
      NSLog(@"%@", [event getEventText]);
  
      _scheduledEvents = [[NSMutableArray alloc] init];
  
      [_scheduledEvents addObject: event];
  
      NSLog(@"%lu", [_scheduledEvents count]);
  
  }
  
  -(NSString*) getAllEventText {
  
      NSString * allEventText;
  
      // loop through NSMutableArray calling each Event's getEventText method using a for loop
  
      for (int i=0; i&lt;[_scheduledEvents count]; i++) {
  
          allEventText = [NSString stringWithFormat:@"Event %d: %@\n", i+1, [_scheduledEvents[i] getEventText] ];
  
          NSLog(@"%@", [_scheduledEvents[i] getEventText]);
  
      }
  
      // return concatenated string
  
      return allEventText;
  
  }
  
  @end
  </code></pre>
  
  <p>ViewController.m:</p>
  
  <pre><code>@implementation ViewController
  
  - (void)viewDidLoad {
      [super viewDidLoad];
  
      Schedule * mySchedule = [[Schedule alloc] init];
  
      [mySchedule addNewEventWithTitle:@"My Birthday" Description:@"My most cherished birthday" andDate:[NSDate dateWithTimeIntervalSinceReferenceDate:484830000]];
  
      [mySchedule addNewEventWithTitle:@"Meeting with the Client" Description:@"My most important meeting" andDate:[NSDate dateWithTimeIntervalSinceReferenceDate:481302000]];
  
      [mySchedule addNewEventWithTitle:@"Appointment with Family Doctor" Description:@"My most urgent appointment" andDate:[NSDate dateWithTimeIntervalSinceReferenceDate:480270000]];
  
      [_outputTextView setText:[mySchedule getAllEventText]];
  
  }
  
  - (void)didReceiveMemoryWarning {
      [super didReceiveMemoryWarning];
      // Dispose of any resources that can be recreated.
  }
  
  @end
  </code></pre>