objective-c - 无法从 NSValue 的 mutableArray 中提取 CGPoint 值

标签 objective-c xcode nsmutablearray cgpoint nsvalue

我制作了一个 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/

相关文章:

iphone - 使用 UIScrollView 从上到下滚动

objective-c - 在Sharekit2.0中自定义发到facebook的帖子

objective-c - 在 Lion 中获取 TFENode 的完整路径

ios - 来自 sqlite 数据库的 NSMutableArray addObject 不起作用

objective-c - 从字典数组中搜索值

objective-c - 我可以在子类中实现协议(protocol)的一个功能吗?

ios - 在 UITabbarController 中使用 UINavigationController

ios - 如何在 Xcode 中更改方案的名称?

ios - Swift:如何实现自定义 AutoSegue

ios - 无法快速将 NSMutableArray 的值存储在 NSUserdefault 中