Is there a way to put a scalar type like CGPoint (or any custom creation) into an NSArray?

Perhaps I could create a class that contains CGPoint as an instance variable such as a wrapper. Does this make sense? I feel uncomfortable with this. Hope there is a better solution.

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

0


a source to share


3 answers


Make an object. You can try this:

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

[NSValue valueWithCGPoint:point];

      



This goes for almost all scalars you want to put in an NSArray:

CGFloat foo = 1.f;

[NSNumber numberWithFloat:foo];

      

+7


a source


NSValue



+1


a source


You can put the CGPoint value into an NSValue object. It is documented in the NSValue UIKit add-ons reference .

+1


a source







All Articles