title: How to break up large struct in Swift
body: <p>I have a struct with 120 variables and 70 constants (is translation from FORTRAN physiological model);  I would like to get the initializations and even the declarations out of the struct code because the file will be several thousand lines of code from the algorithms of the model. Here is some code that I thought would work by using a protocol and extension:</p>
  <pre><code>import Foundation
  
  protocol HasConstants {
      var c1:Double {get set}
      var c2:Double {get set}
  }
  
  extension HasConstants {
      func setConstants() -&gt; () {
          var c1 = 3.4
          var c2 = 9.9
      }
  }
  
  struct macPuf: HasConstants {
      var c1: Double
      var c2: Double
      setConstants()
  }
  </code></pre>
  <p>This does not work.  The compiler complains in the extension function that the variables are never used, and in the MacPuf struct it expects a func keyword and brackets, etc. in what it says is an instance method declaration.</p>
  <p>Basically I would like to be able to have something like:</p>
  <pre><code>struct macPuf {
  #include InitializeConstants. // for example c1
  #include InitializeVariables. // for example var1 .. var45
  var1 = var2 * c1
  etc.
  #include AnotherChunkOfCodeFromExternalFile
  var 45 = functionX(var4 + var 6)
  etc.
  </code></pre>
  <p>I apologize that this is probably a ludicrous question with a ridiculously simple solution. Any assistance is greatly appreciated.</p>