title: Dealing with Swift Optionals and partial JSON representation/responses in REST
body: <p>If my REST API can send partial responses back (as specified here: <a href="https://developers.google.com/gmail/api/guides/performance" rel="nofollow noreferrer">https://developers.google.com/gmail/api/guides/performance</a>), is it best to make all my properties in my Swift objects optional? Or is there an another pattern to handle this?</p>
  
  <p>For example, my user object:</p>
  
  <pre><code>public struct User: Decodable {
      var id: Int
      var firstName: String
      var lastName: String
      var phoneNumber: String?
      var verified: Bool
  }
  </code></pre>
  
  <p>In the DB, only phone number is optional, all the rest are required. Hence, only phone number in my swift object is marked as optional. However when it comes to the API responses, not all requests for user objects will contain all the required properties. For example, if I need to know which users are verified (GET /users?verified=true&amp;fields=id), my response would just be a collection of user ids.</p>
  
  <p>Does that mean that in Swift, I'd need to mark all properties except for id as optional? </p>
  
  <p>Related question on SO: <a href="https://stackoverflow.com/questions/36354704/should-i-use-optional-for-properties-of-object-models-that-will-be-parsed-from-j">Should I use optional for properties of object models that will be parsed from JSON?</a></p>