Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kashmoney2006

macrumors regular
Original poster
Dec 12, 2007
232
0
I am trying to create a tic tac toe program in xcode using objective c in an attempt to learn the language. i was wondering if objective c supports 2-D arrays? that is hove i implemented it in previous languanges but cant figure it out in ObjC. in c++ i used something similar to

Code:
 int board[][]

is this possible in ObjC?
 

SC68Cal

macrumors 68000
Feb 23, 2006
1,642
0
It's standard C syntax. If you want to get fancy I think the NSArray class would be your other option.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
NSMutableArray is an object. You can make an NSArray or NSMutableArray of them, if you want to. Those can be arrays of NSNumbers that you store something in. I wouldn't, though.

I don't know what you want to store, exactly, but I think a single dimension array should suffice for this purpose. If you are having a 3x3 array to store board state, i'd say just use a 9 element array. I'd say just have them be chars. Ints are SO big, after all. You can save *27* bytes assuming 32 bit ints. Then you can store 'X','O', or ' '(or '\0' if you prefer).

I am, of course, being facetious. If you really want to be a glutton for punishment, you should store the board state in a single short(2-byte) integer.

-Lee
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
I am trying to create a tic tac toe program in xcode using objective c in an attempt to learn the language. i was wondering if objective c supports 2-D arrays? that is hove i implemented it in previous languanges but cant figure it out in ObjC. in c++ i used something similar to

Code:
 int board[][]

is this possible in ObjC?

int board [][]

while not work either in C++ or in C or in Objective-C.

int board [10][10] works in all three languages.
 

Shahmeer

macrumors newbie
Mar 25, 2008
6
0
Pakistan
Problem with Socket In Objective-c

hi frndz,
i wana discusss a problem related my Client/server application.
while running properly if i terminate my Server application and then restart,my socket remains busy for about 15 to 30 sec..:confused:
do anyone has any idea?
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
hi frndz,
i wana discusss a problem related my Client/server application.
while running properly if i terminate my Server application and then restart,my socket remains busy for about 15 to 30 sec..:confused:
do anyone has any idea?

try posting in a new thread, and maybe posting a code snippet.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.