0

Probably I could create a class that holds an CGPoint as instance variable, like a wrapper. Does that make sense? I feel uncomfortable with that, though. I hope there is an better solution.

How about any self-created scalar type? Like MyCoolScalarType?

Thanks
  • 40,109
  • 71
  • 208
  • 322
  • By the way, aren't you repeating yourself? http://stackoverflow.com/questions/899600/how-can-i-add-cgpoint-objects-to-an-nsarray-the-easy-way – Kriem May 22 '09 at 20:54
  • 1
    Yes, he doesn't appear to want people to respond in the comments to his previous questions, but likes asking the same question again with slightly different phrasing. – Brad Larson May 23 '09 at 01:33

3 Answers3

7

Make it an object. You could try this:

CGPoint point = CGPointMake(1.f,1.f);

[NSValue valueWithCGPoint:point];

This goes for pretty much every scalar you want to put in an NSArray:

CGFloat foo = 1.f;

[NSNumber numberWithFloat:foo];
Kriem
  • 8,666
  • 16
  • 72
  • 120
  • How about own defined scalar types? like MyCoolScalar? – Thanks May 22 '09 at 20:40
  • 1
    From the NSValue documentation (which you should look through): "An NSValue object is a simple container for a single C or Objective-C data item. It can hold any of the scalar types such as int, float, and char, as well as pointers, structures, and object ids." – Alex Reynolds May 22 '09 at 20:46
  • Alex beat me to it. :) But he's right. So, basically you're still wrapping. But it's a very good and much practiced method. – Kriem May 22 '09 at 20:50
1

NSValue

Remus Rusanu
  • 288,378
  • 40
  • 442
  • 569
1

You can box a CGPoint value into an NSValue object. It is documented in NSValue UIKit Additions Reference.

Chris Lundie
  • 6,023
  • 2
  • 27
  • 28