我想在objective-c中創建一個2d數組,並且我不想使用NSArray
,因爲我使用int並且代碼會很煩人:{[array objectAtIndex:x] objectAtIndex:y]
,更不用說我會擁有將數字從NSNumber
轉換回來...看起來像很多額外的工作。iPhone SDK 2d int數組
我不能執行以下操作嗎?
// .h file
int aTiles[10][2];
// .m file
aTiles = {
{ 0, 0}, // 0
{ 0, 1}, // 1
{ 1, 5}, // 2
{ 0, 0}, // 3
{ 0, 0}, // 4
{ 0, 0}, // 5
};
它一起工作在同一行(int a[x][x] = {...};
),但我需要的數組是公開的,所以我可以從任何函數訪問它。
第二行表示期待分號。
感謝
允許在那裏。 – 2012-01-22 23:19:42
Jon Skeet在這裏給出了一個可愛的解釋:http://stackoverflow.com/questions/7043372/int-a-1-2-weird-comma-allowed-any-particular-reason/7043410#7043410 –
喬恩Skeet - 是你能做的最好嗎? ;-) – Rayfleck