I’m to port some JS to native ObjC code. Since a struct won’t fit inside arrays, it needs to be wrapped.
The JS code goes as follows:
var bezierVertices = [{0: 14},{10: 32},{24: 16}];
Plain and easy JS: Array of anonymous objects.
I’m bound to the following requirement: Have the code as compact as possible, meaning I’ve been refused when proposing an NSArray of NSValue using [NSValue valueWithCGPoint:ccp(x,y)]
Going down the malloc way doesn’t fit this criterion either. They want something as compact as the JS stated above.
Before writing something as ugly as an NSString like @”0:14;10:32;24:16″; that’s split and parsed in a loop, I thought SO could help bring something clean 🙂
I’m allowed to use .mm so ObjC++ solutions could fit as well, but I’m not knowledgeable about C++ at all…
Thanks!
J.
Who’s “they”? Do “they” have any understanding that Objective-C is a compiled language and the “compactness” of the source code is largely irrelevant?
Anyway, rant over. You can make a C array of CGPoints like this:
This is a standard C array initialiser. You get the number of elements like this: