Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何将id类型转换为CGPoint类型?_Ios_Objective C_Nsmutablearray_Nsarray - Fatal编程技术网

Ios 如何将id类型转换为CGPoint类型?

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

我有一个CGPoints数组。当我提取这个数组的存储元素时,我希望它是CGPoint类型而不是id。我如何实现这一点?

我想你所需要的只是一个简单的强制转换

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别担心。请记住接受答案。