对于iPad / iPhone应用程序,如何获得积分? [英] For iPad / iPhone apps, how to have an array of points?

查看:92
本文介绍了对于iPad / iPhone应用程序,如何获得积分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以有一个 NSMutableArray 对象,然后向其中添加对象。

We can have an NSMutableArray object, and add objects to it.

但是 CGPoint 不是对象...是否存在适合添加到NSMutableArray对象的Point对象?

But CGPoint is not an object... are there Point objects suitable to be added to an NSMutableArray object?

我看到一些使用 NSStringFromCGPoint 创建一个 NSString 对象,以便可以将其添加到数组中,并在以后使用 CGPointFromString 来获取 CGPoint ……但这看起来实在是太过分了……

I see some code using NSStringFromCGPoint to create an NSString object so that it can be added to the array, and later use CGPointFromString to get the CGPoint back... but that just looks too much of a hack...

推荐答案

您可以使用 NSValue 作为包装器将点存储在数组中:

You can store the points in the array using NSValue as a wrapper:

CGPoint a = CGPointMake(10.0, 10.0);
[array addObject:[NSValue valueWithCGPoint:a]];

CGPoint b = [(NSValue *)[array objectAtIndex:0] CGPointValue];

这篇关于对于iPad / iPhone应用程序,如何获得积分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆