无法将多个对象添加到NSArray

时间:2019-09-05 14:06:07

标签: objective-c

我有一个for循环,遍历NSrray,从该数组中获取对象,然后将它们添加到另一个NSArray中。我发现只有一个对象被添加到该数组中...我认为这是一个问题是因为只有一个“ TimeSliceinfo”实例?

代码:

for (int z = 0; z < timeProfiles.count; z+= 12) {       

  for (int i = 0; i < 12; i++) {//Time slices (12)

    NSArray *tP = [timeProfiles objectAtIndex:z + i];


    TimeScaleInfo  *timeScaleInfo0 = [[TimeScaleInfo alloc] initWithTimeScaleID:[timeProfiles[0][2] integerValue]  timeSliceID:[[tP objectAtIndex:15] integerValue] timeScaleStartTime:timeProfiles[0][3] timeScaleEndTime:timeProfiles[0][4] weekdayFlag:weekDayFlag0 clendarFlag:@"00000000"];
    TimeScaleInfo  *timeScaleInfo1 = [[TimeScaleInfo alloc] initWithTimeScaleID:[timeProfiles[1][2] integerValue]  timeSliceID:[[tP objectAtIndex:15] integerValue] timeScaleStartTime:timeProfiles[1][3] timeScaleEndTime:timeProfiles[1][4] weekdayFlag:weekDayFlag1 clendarFlag:@"00000000"];
    TimeScaleInfo  *timeScaleInfo2 = [[TimeScaleInfo alloc] initWithTimeScaleID:[timeProfiles[2][2] integerValue]  timeSliceID:[[tP objectAtIndex:15] integerValue] timeScaleStartTime:timeProfiles[2][3] timeScaleEndTime:timeProfiles[2][4] weekdayFlag:weekDayFlag2 clendarFlag:@"00000000"];
    TimeScaleInfo  *timeScaleInfo3 = [[TimeScaleInfo alloc] initWithTimeScaleID:[timeProfiles[3][2] integerValue]  timeSliceID:[[tP objectAtIndex:15]integerValue] timeScaleStartTime:timeProfiles[3][3] timeScaleEndTime:timeProfiles[3][4] weekdayFlag:weekDayFlag3 clendarFlag:@"00000000"];

    timeSliceArray = [NSMutableArray arrayWithCapacity:10000];


    // add timescales to timeslice
    TimeSliceInfo *timesliceInfo = [[TimeSliceInfo alloc] initWithTimeSliceID:[[tP objectAtIndex:15] integerValue]  timeScaleInfoArray:@[timeScaleInfo0, timeScaleInfo1, timeScaleInfo2, timeScaleInfo3, timeScaleInfo4, timeScaleInfo5, timeScaleInfo6, timeScaleInfo7, timeScaleInfo8, timeScaleInfo9, timeScaleInfo10, timeScaleInfo11]];


    //add timeslices
    [timeSliceArray addObject:timesliceInfo];
  }
}

// timeSliceArray only contains a single object
 userKeyInfo.timeSliceInfoArray = timeSliceArray;

0 个答案:

没有答案