How to store CGRect values in NSMutableArray?

后端 未结 4 1003
野性不改
野性不改 2021-01-30 01:20

How would I store CGRect objects in a NSMutableArray, and then later retrieve them?

4条回答
  •  故里飘歌
    2021-01-30 02:05

    You need to wrap the CG structures in NSValue classes. So:

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

提交回复
热议问题