Note that there are some explanatory texts on larger screens.

plurals
  1. POBuild Array with Structure in Objective-C
    primarykey
    data
    text
    <p>I would like to know the process to create a set of letters, assign point values to them (use the game "Scrabble" as reference), and be able to access them via an index number, so I can shuffle and manipulate the order of tiles.... all in Objective-C.</p> <p>I'm using XCode4, and I'm trying to program a simple word game loosely based on Scrabble.</p> <p>I was able to do this in C by creating a structure to hold the different variables of a letter block.</p> <pre><code>struct singleTile { char letter; int value; }; </code></pre> <p>Another structure that held an array, storing the data for each letter.</p> <pre><code>struct singleTile set[] = { {"A", 1}, {"B", 4}, {"C", 4}, {"D", 2}, ...etc. } </code></pre> <p>I'm able to display the information about each letter via an index number.</p> <pre><code>printf("The second letter is %s and is worth %d points\n", set[2].letter, set[2].value); </code></pre> <p>How do I translate this into Objective-C? I've read some tutorials about NSArrays and NSMutableArrays, but I haven't found examples of these arrays that hold more than one piece of information, like mine above (specifically a letter and a value).</p> <p>Please don't type everything out, unless you feel inclined to do so. If you explain the process and/or logic to me and point me in the right direction, I should be able to figure out how to program it.</p> <p>In the future, I'd like to have each tile hold more information beyond a letter and a value, so this basic lesson that I can't hurdle is important to me.</p> <p>I appreciate your time and generosity.</p> <p>Thank you in advance. -Jeff</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload