@@ -545,27 +545,33 @@ - (void)startStoppedViewsInternal
545
545
{
546
546
// Create an array to store keys for views that need to be removed
547
547
NSMutableArray <NSString *> *keysToRemove = [NSMutableArray array ];
548
-
548
+ NSMutableArray <NSString *> *keysToStart = [NSMutableArray array ];
549
+
550
+ // Collect keys without modifying the dictionary
549
551
[self .viewDataDictionary enumerateKeysAndObjectsUsingBlock: ^(NSString * _Nonnull key, CountlyViewData * _Nonnull viewData, BOOL * _Nonnull stop) {
550
552
if (viewData.willStartAgain )
551
553
{
552
- NSString *viewID = [self startViewInternal: viewData.viewName customSegmentation: viewData.startSegmentation isAutoStoppedView: viewData.isAutoStoppedView];
553
-
554
- // Retrieve the newly created viewData for the viewID
555
- CountlyViewData* viewDataNew = self.viewDataDictionary [viewID];
556
-
557
- // Copy the segmentation data from the old view to the new view
558
- viewDataNew.segmentation = viewData.segmentation .mutableCopy ;
559
-
560
- // Add the old view's ID to the array for removal later
554
+ [keysToStart addObject: key];
561
555
[keysToRemove addObject: viewData.viewID];
562
556
}
563
557
}];
564
558
559
+ // Start the collected views after enumeration
560
+ for (NSString *key in keysToStart)
561
+ {
562
+ CountlyViewData *viewData = self.viewDataDictionary [key];
563
+ NSString *viewID = [self startViewInternal: viewData.viewName customSegmentation: viewData.startSegmentation isAutoStoppedView: viewData.isAutoStoppedView];
564
+
565
+ // Retrieve and update the newly created viewData
566
+ CountlyViewData *viewDataNew = self.viewDataDictionary [viewID];
567
+ viewDataNew.segmentation = viewData.segmentation .mutableCopy ;
568
+ }
569
+
565
570
// Remove the entries from the dictionary
566
571
[self .viewDataDictionary removeObjectsForKeys: keysToRemove];
567
572
}
568
573
574
+
569
575
- (void )stopAllViewsInternal : (NSDictionary *)segmentation
570
576
{
571
577
// TODO: Should apply all the segmenation operations here at one place instead of doing it for individual view
0 commit comments