Discuss CGPoint into an NSArray? at the iPhone Developer Exchange - Hackint0sh.org; In coding for the iPhone, I've come across this problem..
I know you need to ...
CGPoint into an NSArray?
In coding for the iPhone, I've come across this problem..
I know you need to put Objects into NSArrays (and variants), and a CGPoint being a struct will not work. I don't want to use regular C array notation because I'd like to utilize the dynamic power of the NSMutableArray. I'd rather not have to encapsulate the CGPoint struct in a class.. it just seems so unnecessary.
What to do?
You will have to wrap it in a class. Lemme know if there's a NSStringFromCGPoint() or NSValue class that works for you. (I'm not on my dev machine at the moment.)
it appears (more often than not) that you will have to do things you dont want to, or shouldnt have to, in the official iphone sdk. Not to say that it follows any pattern or reason devoted to any legitimate thought process.
The reason for the class wrapper is simple and expected.
There are three options:
1) Make a simple C array. (or linked list of arrays)
2) Make a class of NSMutableArray which handles only struct instead of objects.
3) Wrap the structs in objects and put them in NSMutableArray.
The problem is #1 is that he wanted the dynamic insertion features of NSMutableArray.
The benefit of #1 is that it's the fastest because you optimize everything to your situation.
The problem with #2 is that Apple would need to write a new class AND it'll be slower than doing it all in C. There is little reason to do this really especially since it's obvious there's a lot of more important stuff Apple still needs to work on in the iPhone.
Based on what typewriter said, #3 was the most reasonable for his tasks. I didn't say it was the best idea. It's simply good enough for most people.