title: Functions and returning values
body: <p>I am a beginner in Swift so some things aren't quite clear to me yet. I hope somebody would explain this to me:</p>
  
  <pre><code>// Creating Type Properties and Type Methods
  class BankAccount {
  
      // stored properties
      let accountNumber: Int
      let routingCode = 12345678
      var balance: Double
      class var interestRate: Float {
          return 2.0
      }
  
      init(num: Int, initialBalance: Double) {
          accountNumber = num
          balance = initialBalance
      }
  
      func deposit(amount: Double) {
          balance += amount
      }
  
      func withdraw(amount: Double) -&gt; Bool {
          if balance &gt; amount {
              balance -= amount
              return true
          } else {
              println("Insufficient funds")
              return false
          }
      }
  
      class func example() {
          // Type methods CANNOT access instance data
          println("Interest rate is \(interestRate)")
      }
  } 
  
  var firstAccount =  BankAccount(num: 11221122, initialBalance: 1000.0)
  var secondAccount = BankAccount(num: 22113322, initialBalance: 4543.54)
  
  BankAccount.interestRate
  
  firstAccount.deposit(520)
  </code></pre>
  
  <p>So this is the code. I am wondering why <code>deposit()</code> doesn't have a return arrow and return keyword and <code>withdraw()</code> does. When do I use a return arrow, in what situations, is there a rule or something? I don't understand.</p>
  
  <p>In addition...
  Everyone is so kind with your answers, it is getting clearer to me now.</p>
  
  <p>In beginning of this tutorial there is practice code for functions</p>
  
  <pre><code>// Function that return values
  func myFunction() -&gt; String {
      return “Hello”
  }
  </code></pre>
  
  <p>I imagine this return value is not needed here but in tutorial they wanted to show us that it exists, am I right?</p>
  
  <p>Furthermore, can I make a "mistake" and use return arrow and value in my deposit function somehow? I tried with this:</p>
  
  <pre><code>func deposit(amount : Double) -&gt; Double {
      return balance += amount
  }
  </code></pre>
  
  <p>... but it generated error.</p>
  
  <p>I saw advanced coding in my last firm, they were creating online shop with many custom and cool features and all code was full of return arrows. That confused me and I thought that it is a default for making methods/functions in OOP.</p>
  
  <p><strong>Additional question!</strong>
  I wanted to play with functions so I want to create a function transferFunds() which transfers money from one account to another. I made function like this</p>
  
  <pre><code>func transferFunds(firstAcc : Int, secondAcc : Int, funds : Double) {
       // magic part
       if firstAcc == firstAccount.accountNumber {
            firstAccount.balance -= funds
       } else {
           println("Invalid account number! Try again.")
       }
  
       if secondAcc == secondAccount.accountNumber {
            secondAccount.balance += funds
       } else {
           println("Invalid account number! Try again.")
       }
  }
  </code></pre>
  
  <p>This is a simple code that came to my mind but I know it is maybe even stupid. I know there should be a code that check if there is enough funds in first account from which I am taking money, but okay... Lets play with this. 
  I want to specify <code>accountNumbers</code> or something else in parameters within function <code>transferFunds()</code> and I want to search through all objects/clients in my imaginary bank which use class <code>BankAccount</code> in order to find one and then transfer money. I don't know if I described my problem correctly but I hope you  understand what I want to do. Can somebody help me, please?</p>