ios - Create an array of CGPoints by pairing values from two different NSArrays -
how create array of cgpoints pairing values 2 different nsarrays in objective-c?
lets have array "a" values: 0, 1, 2, 3, 4
, have array "b" values: 21, 30, 33, 35, 31
i create array "ab" cgpoint values: (0,21), (1,30), (2,33), (3,35), (4,31)
thanks help.
note objective-c collection classes can hold objects, have assumed input numbers held in nsnumber
objects. means cgpoint
struct
s must held in nsvalue
object in combined array:
nsarray *array1 = ...; nsarray *array2 = ...; nsmutablearray *pointarray = [[nsmutablearray alloc] init]; if ([array1 count] == [array2 count]) { nsuinteger count = [array1 count], i; (i = 0; < count; i++) { nsnumber *num1 = [array1 objectatindex:i]; nsnumber *num2 = [array2 objectatindex:i]; cgpoint point = cgpointmake([num1 floatvalue], [num2 floatvalue]); [pointarray addobject:[nsvalue valuewithcgpoint:point]]; } } else { nslog(@"array count mis-matched"); }
ios objective-c nsarray cgpoint
No comments:
Post a Comment