title: Swift view model: function vs setter with side effect
body: <p>I need some opinion on view model architecture, in my project I need a view model for a screen that displays a game preparation status, say I need more than 3 players to start game, and the view model has a string property for the status, and I have in my view controller an array of players retrieved from API.</p>
  
  <p><strong>Option 1:</strong></p>
  
  <pre><code>// `gameStatusLabel` is a get property and only set internally when
  // updating players via function
  class GameStatusViewModel: NSObject {
  
    private(set) var gameStatusLabel: String
  
    func updatePlayers(players: [Player]?) {
      if let players = players, players.count &gt; 3 {
        gameStatusLabel = "Ready to start"
      } else {
        gameStatusLabel = "Not enough player(s)"
    }
  }
  </code></pre>
  
  <p><strong>Option 2:</strong></p>
  
  <pre><code>// `gameStatusLabel` is a computed property based on `players.count`
  
  class GameStatusViewModel {
  
      weak var players: [Player]?
  
      var gameStatusLabel: String {
          if let players = self.players {
              if players.count &gt; 3 {
                  return "Ready to start"
              }
          }
          return "Not enough player(s)"
      }
  }
  </code></pre>
  
  <p>Since I'm new to Swift so I want to ask which option above is better, and why? (or alternatively if there's any other better option)</p>
  
  <p><strong>Option 1</strong> doesn't store players model in the view model since it doesn't need to keep a reference to <code>players</code>, and <code>players</code> is only needed for updating the <code>gameStatusLabel</code>, whereas <strong>Option 2</strong> keeps a weak reference to players and makes <code>gameStatusLabel</code> a computed property, the problem here is that <code>players</code> in <strong>Option 2</strong> only need a setter, I don't know if I can have only a setter for a property without a getter (this seems to be the way of <strong>Option 1</strong>).</p>
  
  <p>Thanks in advance!</p>