I have a class, called Schedule, with 4 properties in it:
@interface Schedule : NSObject {
}
@property (strong, nonatomic) NSDate *apptStartTime;
@property (strong, nonatomic) NSDate *apptEndTime;
@property (strong, nonatomic) NSString *clientKey;
@property (strong, nonatomic) NSString *scheduleName;
-(BOOL) occursOnDate: (NSDate *) dateOfAppointment;
@end
I have another class where I have previously created two "Schedule" objects (for testing) with data and put both in a NSMutableSet. This is the code for that:
// schedule1
Schedule *schedule1 = [[Schedule alloc]init];
schedule1.apptStartTime = scheduleStartDate; // today's date
schedule1.apptEndTime = [scheduleStartDate dateByAddingTimeInterval:60*60]; // add 1 hour
schedule1.clientKey = @"GeoffMarsh3911";
schedule1.scheduleName = @"schedule1";
// schedule2
Schedule *schedule2 = [[Schedule alloc]init]; // two days after schedule1
schedule2.apptStartTime = [scheduleStartDate dateByAddingTimeInterval:timeInterval*2]; // add two days to first appointment
schedule2.apptEndTime = [schedule2.apptStartTime dateByAddingTimeInterval:60*60]; // add 1 hour tpo start of appointment
schedule2.clientKey = @"KellieJellyBelly3878";
schedule2.scheduleName = @"schedule2";
// create NSMutableSet for schedule objects
NSMutableSet *setOfSchedules = [NSMutableSet setWithCapacity:5];
[setOfSchedules addObject:schedule1];
[setOfSchedules addObject:schedule2];
Now, I have another class where I try to take the schedules that are in the NSMutableSet and put them in a NSArray so I can work with them, like this:
NSArray *scheduleList = [setOfSchedules allObjects];
The problem is I don't seem to be able to get to the fields within the scheduleList, like apptStartTime, so I can work with it (compare against another date, etc).
Is there a better way of doing this, rather than putting the NSMutableSet in a NSArray? And how do I access the individual fields in the NSArray?
You need to get the object from the NSArray like this:
Schedule *schedule = [scheduleList objectAtIndex:0];
And then access the properties of the schedule
object as usual.
myTime = schedule.apptStartTime;
Although it doesn't make much sense having your objects both in the NSMutableSet and the NSArray. Maybe you could get rid of one of them?