title: Does Swift guarantee the storage order of fields in classes and structs?
body: <p>In C, the order in which you define fields in a struct is the order in which they will be instantiated in memory. Taking into account memory alignment, the following struct will have a size of 8 bytes in memory as shown, but only 6 bytes if the fields are reversed as there doesn't need to be any alignment padding.</p>
  
  <pre><code>struct s {
      int32_t a;
      /* 2 bytes of padding to align a 64 bit integer */
      int64_t b;
  }
  </code></pre>
  
  <p>This ordering guarantee is present in C structs, C++ classes (and structs), and Objective-C classes.</p>
  
  <p>Is the order of storage similarly guaranteed for fields in Swift classes and structs? Or (given that the language doesn't support pointers in the same way as the others listed), does the compiler optimally re-arrange them for you at compile-time?</p>