title: Swift - Append to array in struct
body: <p>I am currently learning swift and am experimenting with data structures. In may code I have certain routines with a name(String) and several tasks(Array of Strings). These values are in a structure.</p>
  
  <p>So I am trying to add another value to the array after it has been initialized. My code is actually working, however I really think it very weird and odd and DO NOT think, that it is the way it should be done. </p>
  
  <pre><code>var routineMgr: routineManager = routineManager();
  struct routine{
      var name = "Name";
      var tasks = [String]();
  }
  
  class routineManager: NSObject {
  var routines = [routine]();
  
  func addTask(name: String, desc: String){
      //init routines with name and an array with certain values, here "Hallo" &amp; "Moin"
      routines.append(routine(name: name, tasks: ["Hallo","Moin"]));
  
   //so i just put this part here to make the example shorter, but it would be in ad different function to make more sense
  
      //adding a new value ("Salut") to the tasks array in the first routine
      //getting current array
      var tempArray = routines[0].tasks;
      //appending new value to current value
      tempArray.append("Salut");
      //replacing old routine with a copy (same name), but the new array (with the appended salut)
      routines[0] = routine(name: routines[0].name, tasks: tempArray);
  }  
  }
  </code></pre>
  
  <p>I have tried some (to me) "more correct" ways, like:</p>
  
  <pre><code>routines[0].tasks.append("Salut");
  </code></pre>
  
  <p>But I always got tons of errors, which I also did not understand.</p>
  
  <p>So my question now: How is it actually done correctly? And why does the second way not work? </p>
  
  <p>Your help and advice is really appreciated!</p>