Ios 如何将id类型转换为CGPoint类型?
我有一个CGPoints数组。当我提取这个数组的存储元素时,我希望它是CGPoint类型而不是id。我如何实现这一点?我想你所需要的只是一个简单的强制转换Ios 如何将id类型转换为CGPoint类型?,ios,objective-c,nsmutablearray,nsarray,Ios,Objective C,Nsmutablearray,Nsarray,我有一个CGPoints数组。当我提取这个数组的存储元素时,我希望它是CGPoint类型而不是id。我如何实现这一点?我想你所需要的只是一个简单的强制转换 CGPoint point = [yourArray[1] CGPointValue]; 你需要做一些像 CGPoint yourPoint = CGPointMake(100, 100); NSValue *pointValueObject = [NSValue valueWithCGPoint:yourPoint]; [myMuta
CGPoint point = [yourArray[1] CGPointValue];
你需要做一些像
CGPoint yourPoint = CGPointMake(100, 100);
NSValue *pointValueObject = [NSValue valueWithCGPoint:yourPoint];
[myMutableArray addObject:pointValueObject];
NSValue *objectFromArray = [myMutableArray lastObject];
CGPoint pointFromArray = [objectFromArray CGPointValue];
这将把
CGPoint
存储到一个可变数组中,然后再次将其取出,并将其转换回CGPoint
显示数组创建方式的代码。不能在数组中存储CGPoint。你是说价值吗?能否显示将cgpoint添加到数组中的代码?[colEndPoint addObject:[NSValue valueWithCGPoint:point2];这是代码:for(int i=0;colEndPoint.count;i++){[self lineTo:[colEndPoint objectAtIndex:i]];}-(void*)lineTo:(CGPoint)p1{}是的,它以NSvalue的形式存储在数组中。谢谢。这就是我要找的。@user301201别担心。请记住接受答案。