title: Convert C# function into Swift 4.2
body: <p>I found <a href="https://forum.unity.com/threads/2d-tile-bitmasking.513840/" rel="nofollow noreferrer">this thread</a> talking about <a href="https://gamedevelopment.tutsplus.com/tutorials/how-to-use-tile-bitmasking-to-auto-tile-your-level-layouts--cms-25673" rel="nofollow noreferrer">this article</a>. I found some code in the thread which <em>appears</em> to be exactly what I need for my project. But, it is in C# and I have no idea how to translate it into Swift.</p>
  
  <p>C# Code:</p>
  
  <pre><code>[Flags]
  public enum Directions
  {
      NorthWest  = 1 &lt;&lt; 0,
      North = 1 &lt;&lt; 1,
      NorthEast   = 1 &lt;&lt; 2,
      West   = 1 &lt;&lt; 3,
      East  = 1 &lt;&lt; 4,
      SouthWest = 1 &lt;&lt; 5,
      South   = 1 &lt;&lt; 6,
      SouthEast   = 1 &lt;&lt; 7,
  }
  
  private static Directions CalculateTileFlags(bool east, bool west, bool north, bool south, bool northWest, bool northEast, bool southWest, bool southEast)
  {
      var directions = (east ? Directions.East : 0) | (west ? Directions.West : 0)  | (north ? Directions.North : 0) | (south ? Directions.South : 0);
      directions |= ((north &amp;&amp; west) &amp;&amp; northWest) ? Directions.NorthWest : 0;
      directions |= ((north &amp;&amp; east) &amp;&amp; northEast) ? Directions.NorthEast : 0;
      directions |= ((south &amp;&amp; west) &amp;&amp; southWest) ? Directions.SouthWest : 0;
      directions |= ((south &amp;&amp; east) &amp;&amp; southEast) ? Directions.SouthEast : 0;
      return directions;
  }
  </code></pre>
  
  <p>My Attempt so far:</p>
  
  <pre><code>var Flags = [Int]()
  enum Directions : Int {
      case NorthWest
      case North
      case NorthEast
      case West
      case East
      case SouthWest
      case South
      case SouthEast
  
      func getTuple() -&gt; Int {
          switch self {
          case .NorthWest:
              return 1 &lt;&lt; 0
          case .North:
              return 1 &lt;&lt; 1
          case .NorthEast:
              return 1 &lt;&lt; 2
          case .West:
              return 1 &lt;&lt; 3
          case .East:
              return 1 &lt;&lt; 4
          case .SouthWest:
              return 1 &lt;&lt; 5
          case .South:
              return 1 &lt;&lt; 6
          case .SouthEast:
              return 1 &lt;&lt; 7
          }
      }
  }
  </code></pre>
  
  <p>I got that part. It was easy. The function is the part I can't quite figure out. I think I am close, but I don't know. </p>
  
  <pre><code>func CalculateTileFlags(east: Bool, west: Bool, north: Bool, south: Bool,
                              northWest: Bool, northEast: Bool, southWest: Bool, southEast: Bool) -&gt; Int {
  
      var eastD = Directions.East.getTuple()
      var westD = Directions.West.getTuple()
      var northD = Directions.North.getTuple()
      var southD = Directions.South.getTuple()
      var northWestD = Directions.NorthWest.getTuple()
      var northEastD = Directions.NorthEast.getTuple()
      var southWestD = Directions.SouthWest.getTuple()
      var southEastD = Directions.SouthEast.getTuple()
  
      var directions = east ? true : false || west ? true : false || north ? true : false || south ? true : false
  
      directions != ((north &amp;&amp; west) &amp;&amp; northWest) ? northWestD : 0
      directions != ((north &amp;&amp; east) &amp;&amp; northEast) ? northEastD : 0
      directions != ((south &amp;&amp; west) &amp;&amp; southWest) ? southWestD : 0
      directions != ((south &amp;&amp; east) &amp;&amp; southEast) ? southEastD : 0
  
      return directions
  }
  </code></pre>
  
  <p>I need help translating this function correctly so that it returns 47 possible integers below 255. </p>