title: Swift class function returning empty after for-in loop
body: <p>I am trying to build a simple Library-Shelf-Book model in Swift and I am running into a strange issue. Within the following Library Class, my func total book count is returning 0 every time. I know its probably something simple I'm overlooking but any help would be awesome. Here is my library class:</p>
  
  <pre><code>class Library
  {
  
  var allShelves:[Shelf]=[]
  var allBooksCount = 0
  
  var description: String{
      return "This Library has \(allShelves.count) Shelves with \(allBooksCount) books"
  }
  
  func addNewShelf(newShelf: Shelf){
      var newShelf = Shelf()
      self.allShelves.append(newShelf)
      println("There are \(allShelves.count) SHELVES in this library")
  
  }
  
  func totalBookCount() -&gt; Int{
      for currentShelf in allShelves{
          allBooksCount = currentShelf.numberOfBooks
      }
      return allBooksCount
  }
  
  
  }
  </code></pre>
  
  <p>Here is my Shelf class:</p>
  
  <pre><code>class Shelf
  {
  
  var allBooksOnShelf:[Book] = []
  var numberOfBooks = 0
  
  init(){
      self.allBooksOnShelf = []
  }
  
  var description: String{
      return "This Shelf has \(allBooksOnShelf.count) Books"
  }
  
  func addNewBook(newBookToAddToShelf: Book){
      let newBook = Book(bookName: newBookToAddToShelf.bookName)
      self.allBooksOnShelf += [newBookToAddToShelf]
      numberOfBooks = allBooksOnShelf.count
      println("new book called \(newBook.bookName)")
  
  }
  }
  </code></pre>
  
  <p>Here are my tests:</p>
  
  <pre><code>let newLibrary = Library()
  //println(newLibrary.description)
  
  
  let libraryShelf1 = Shelf()
  newLibrary.addNewShelf(libraryShelf1)
  
  let libraryShelf2 = Shelf()
  newLibrary.addNewShelf(libraryShelf2)
  
  libraryShelf1.addNewBook(Book(bookName: "Game Of Thrones"))
  libraryShelf1.addNewBook(Book(bookName: "Hunger Games"))
  libraryShelf1.addNewBook(Book(bookName: "Return of the Jedi"))
  
  println("this Shelf has \(libraryShelf1.allBooksOnShelf.count) books")
  
  newLibrary.totalBookCount()
  
  println(newLibrary.description)
  </code></pre>
  
  <p>newLibrary.totalBookCount() always returns 0.</p>