title: iOS Swift Data Design Confusion
body: <p>As an exercise in learning Swift/iOS, I have begun coding an adaptation of a mildly complex adventure board-game. In this game, players often end up with cards that represent objects. Each such card has a rule associated with it, usually fairly simple. There are well over 100 unique cards.</p>
  
  <p>In laying out my coding design, I keep running into the same problem, along the following lines:</p>
  
  <pre><code>Class ItemCard {
      var name: String = “motorcycle”
      var cardImage = &lt;&lt; filename information for where the card image is &gt;&gt;
      &lt;&lt; rule: maxSpeed += 3 &gt;&gt;
  }
  </code></pre>
  
  <p>Now if I do this card by card, it’s easy enough, but it’s also an insane amount of code to do very, very little. Absolute brute-force method. At base, this isn’t any better:</p>
  
  <pre><code>    switch cardName {
      case “Motorcycle”:
          &lt;&lt; call the motorcycle function &gt;&gt;
      case “Boat”:
          &lt;&lt; etc. etc. etc. &gt;&gt;
      }
  </code></pre>
  
  <p>Obviously I can abstract somewhat: all cards that adjust certain kinds of stats call function adjustStat(nameOfStatAdjusted, byHowMuch). But somewhere I still have to have an extended definition that says that objects which are instances of .motorcycle take this function, which reverts me right back to brute force lists of every single item with a longish stream of code.</p>
  
  <p>It seems to me that there has to be a clean way to:</p>
  
  <ol>
  <li>Put the relevant data into some kind of list files from which it can be extracted exclusively when a player draws a given card, and then de-initiated when that card leaves play for one reason or another; AND</li>
  <li>Have appropriate base classes for different kinds of cards, different general categories of items, etc.</li>
  </ol>
  
  <p>... and all of this without using 10+ lines of code for every single card individually.</p>
  
  <p>What am I misunderstanding about data structures in iOS? Is this something I should be doing with CoreData or Realm or something?</p>