数组插值与取值

来源:互联网 发布:宠爱之名护肤品知乎 编辑:程序博客网 时间:2024/04/29 10:10
  • CGPoint放入数组的过程:

NSArray *array=[NSArray arrayWithObjects:NSStringFromCGPoint(0.0f,0.0f),NSStringFromCGPoint(0.0f,0.0f),nil];

  • 从数组中取值的过程:

CGPoint point=CGPointFromNSString([array objectAtIndex:2]);

  • 用NSValue进行统一存储也不错,NSValue可以包装任何值

NSRect *rect = NSRectMake(1,2,20,30);
NSValue *value = [NSValue valueWithByte:&rect ObjCType:@encode(NSRect)];
[array addObject:value];

NSRect *getRect = [NSValue getValue:&rect];