Pregunta

I am working on mapView project. My project will take only 5 annotations on the map. Once new annotation will be added, then first annotation will be drop. I am keeping all annotations latitude and longtitude into NSMutableStringArray. Is there any short way to implement this round robin fashion. First in last out.

for example my nsmutable string:

 [12.99, 35.97: 35.85,94.53: 45.44,98.91]

How could I delete first object (each string separated by column operator :) from the string to acquire the following:

 [35.85,94.53: 45.44,98.91]
¿Fue útil?

Solución 2

I have got it work, my solution is below:

NSMutableString *absolute=[NSMutableString stringWithString:pinPoints];
          NSLog(@"before absolute: %@",absolute);

          NSArray *placemarks=[absolute componentsSeparatedByString:@":"];
          if([placemarks count]>5)
          {
          //NSLog(@"%@",[placemarks objectAtIndex:0]);
          NSMutableString *string1 = [NSMutableString stringWithString: [placemarks objectAtIndex:0]];
          [absolute replaceOccurrencesOfString:string1 withString:@"" options:0 range:NSMakeRange(0,[pinPoints length])];
          pinPoints=absolute;
          }
          NSLog(@"after absolute: %@",absolute);

Otros consejos

Whats wrong with using the NSMutableArray itself. or maybe I didnt understand your question?

NSMutableArray *queue = [[NSMutableArray alloc] init];

if([queue count] >= 5)
    [queue addObject: myObject];  // adds at end
else
    object = [queue objectAtIndex:5];  // take out the first added object
    [queue removeObjectAtIndex:0];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top