title: How to Write Macros in Swift
body: <p>For example, we can use macros in C++ to write a simplified version of a similar name, as in the source code below, but can you do the same in Swift?</p>
  <pre class="lang-cpp prettyprint-override"><code>void AddStats(const Stats&amp; add_from, Stats* add_to) {
      add_to-&gt;set_total_memory(add_from.total_memory() + add_to-&gt;total_memory());
      add_to-&gt;set_free_memory(add_from.total_memory() + add_to-&gt;free_memory());
      add_to-&gt;set_swap_memory(add_from.total_memory() + add_to-&gt;swap_memory());
      add_to-&gt;set_status_string(add_from.total_memory() + add_to-&gt;status_string());
      add_to-&gt;set_num_processes(add_from.total_memory() + add_to-&gt;num_processes());
      ...
  }
  </code></pre>
  <p>We can write the above in the following way.</p>
  <pre class="lang-cpp prettyprint-override"><code>
  void AddStats(const Stats&amp; add_from, Stats* add_to) {
      #define ADD_FIELD(field) add_to-&gt;set##field(add_from.field() + add_to-&gt;field())
      ADD_FIELD(total_memory);
      ADD_FIELD(free_memory);
      ADD_FIELD(swap_memory);
      ADD_FIELD(status_string);
      ADD_FIELD(num_processes);
      ...
      #undef ADD_FIELD
  }
  </code></pre>
  <p>I want to write the same way in Swift, but I don't know how.
  Can someone please tell me how to do it?</p>
  <pre class="lang-swift prettyprint-override"><code>
  import SwiftUI
  
  enum testEnum: String{
      case hoge
      case tage
      case hige
  }
  
  
  private let hoge = 1
  private let tage = 2
  private let hige = 3
  
  
  struct Content: View{
      let num: testEnum = .hoge
      var body: some View {
          if num == .hoge {
              Text(&quot;\(hoge)&quot;)
          } else if num == .tage {
              Text(&quot;\(tage)&quot;)
          } else if num == .hige {
              Text(&quot;\(hige)&quot;)
          }
          
      }
  }
  </code></pre>