iosobjective-cnsmutablearray

how to alter NSMutableArray in an specific array


I have a NSMutableArray which holds a Custom class of MKMapkit.

MapPoint *placeObject = [[MapPoint alloc] initWithTitle:title subtitle:subtitle coordinate:loc description:description storeImage:storeImage];
[annotationArray addObject:placeObject];

My routine fills the placeObject without the image because they will load asynchronously and finished after a couple of seconds. Now my questions is: Is there a way to alter the placeObject which is within the annotationArray?

EDIT

To display my issue in a better way here some code parts:

if (annotationArray == nil)
{
    [self setAnnotationArray:[[NSMutableArray alloc] init]];
}
for (NSDictionary *locationDetails in parser.items)
{
    __block NSData *storeImageData;
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
    dispatch_async(queue, ^{
        storeImageData = [NSData dataWithContentsOfURL:storeImageURL];
        
        dispatch_sync(dispatch_get_main_queue(), ^{
            UIImage *storeImageTMP = [UIImage imageWithData:storeImageData];
            counterBlock ++;
            NSLog(@"async: %d", counterBlock);
            [imageArray addObject:storeImageTMP];
            });
        });
MapPoint *placeObject = [[MapPoint alloc] initWithTitle:title subtitle:subtitle coordinate:loc description:description storeImage:storeImage];
[annotationArray addObject:placeObject];
}
[mapView addAnnotations:annotationArray];

after this is done: dispatch_queue_t will start working. So I check every 2 seconds if its fully loaded. Then I start to alter annotationArray and refresh my annotations (remove all -> add to map which additional image)

- (void) checkMap
{
    if (counterBlock == 547)
    {
        for (int i=0; i<=counterBlock; i++)
        {
            MapPoint *point = annotationArray[i];
            point.storeImage = imageArray[i];
        }
        if(timer)
        {
            [timer invalidate];
            timer = nil;
        }
        [mapView removeAnnotations:mapView.annotations];
        [mapView addAnnotations:annotationArray];
    }
}

Solution

  • All you need to do is get a reference to one of the MapPoint objects in the array. Then you can set properties and/or call methods on the object as needed.

    MapPoint *point = annotationArray[x]; // x is whatever index you need
    point.image = ... // some image