我制作了一个 CGpoints 的 NSMUtableArray,并通过子类化为 NSValue 来存储它们,但我无法取出这些值。这是我所做的。
CGPoint graphPoint;
NSMutableArray *pointValues = [[NSMutableArray alloc] init];
for( int x =0;x<5; x++)
{
NSDictionary* xValue = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:x] forKey:@"X"];
graphPoint.x =x;
graphPoint.y = [CalculatorBrain runProgram: self.graphingPoint usingVariableValues:xValue];
[pointValues addObject:[NSValue valueWithCGPoint:graphPoint]];
}
我尝试使用它来获取值,但我只是得到 null
for( int x=0; x<5; x++) {
NSValue *val = [pointValues objectAtIndex:x];
CGPoint point = [val CGpointValue];
NSLog(@"Points = %@", point);
}
最佳答案
您无法使用 %@
格式说明符打印 CGPoint
,因为它不是对象。相反,使用 NSStringFromCGPoint()
:
NSLog(@"%@", NSStringFromCGPoint(myPoint));
关于objective-c - 无法从 NSValue 的 mutableArray 中提取 CGPoint 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11604894/