2015-10-08 32 views

回答

1

如果你想打印的所有價值,就需要遍歷整個數組:

for (size_t i = 0; i < CAPACITY; i++) 
    NSLog(@"Point %zu = (%f, %f)", i, pointsBuffer[i].x pointsBuffer[i].y); 

它是如何有用的代碼?本教程在步驟2中解釋它。

-1

這是一個100點的數組。

可以的NSLog

如果不在數組索引分配點,它將返回X = 0,Y爲默認點值= 0

NSLog(@"point(%f,%f)",pointsBuffer[0].x,pointsBuffer[0].y); 

可以分配值成陣列指數

pointsBuffer[1].x = 120.0; 
pointsBuffer[1].x = 130.0; 
NSLog(@"point(%f,%f)",pointsBuffer[1].x,pointsBuffer[1].y); 
+0

做我做錯什麼? – Jamil

+1

本地聲明的數組未被初始化爲0.其值爲垃圾。 –

+0

它可能會垃圾,但它會一直爲0,你可以用這個值來比較任何東西 – Jamil

1

CGPoint數組,你想是這樣的:

for (int capacityIndex = 0; capacityIndex < CAPACITY; capacityIndex++) { 
    NSLog(@"%@", NSStringFromCGPoint(pointsBuffer[capacityIndex])); 
} 

或者打印的特定點:

NSLog(@"%@", NSStringFromCGPoint(pointsBuffer[5])); // To print 6th point.