iphone nsmutablearray core-graphics

iphone - ¿Cómo almacenar los valores de CGRect en NSMutableArray?



core-graphics (4)

Almacenamos los CGRect , CGPoint , CMTime en un NSMutableArray ,

[arrayName addObject:[NSValue valueWithCGPoint:MyCGPoint]]

[arrayName addObject:[NSValue valueWithCGRect:MyCGRect]]

[arrayName addObject:[NSValue valueWithCMTime:MyCMTime]]

[arrayName addObject:[NSValue valueWithCMTimeRange:MyCMTimeRange]]

¿Cómo puedo almacenar objetos CGRect en un NSMutableArray y luego recuperarlos?


NSValue envolver las estructuras CG en clases NSValue . Asi que:

NSMutableArray* array = [NSMutableArray mutableArray]; [array addObject:[NSValue valueWithCGRect:CGRectMake(0,0,10,10)]]; CGRect someRect = [[array objectAtIndex:0] CGRectValue];


CGRect rect = CGRectMake( 5, 5, 40, 30 ); NSString* rectAsString = NSStringFromCGRect( rect ); CGRect original = CGRectFromString( rectAsString );

¿Qué piensas de esta forma de almacenar las fechas de CGRect?


Store string in array.and then get back string and convert that in CGRect back as per the need. CGRect rect = CGRectMake( 5, 5, 40, 30 ); NSString* rectAsString = NSStringFromCGRect( rect ); NSMutableArray* array = [NSMutableArray mutableArray]; [array addObject:rectAsString]; For converting string in CGRect back use:- CGRect rect9 = CGRectFromString(rectAsString);