title: Swift how to "pass by value" of a object
body: <p>I am quite new in Swift. And I create a class(for example):</p>
  
  <pre><code>class Fraction{
      var a: Int
      init(a:Int){
          self.a = a
      } 
      func toString() -&gt; String{
          return "\(self.a)"
      }
  }
  </code></pre>
  
  <p>and I also build a in other class function:</p>
  
  <pre><code>class func A_plusplus(f:Fraction){
      f.a++
  }
  </code></pre>
  
  <p>Then in the executive class I write:</p>
  
  <pre><code>var object = Fraction(a:10)
  print("before run func = " + object.toString())
  XXXclass.A_plusplus(object)
  print("after ran func =" + object.toString() )
  </code></pre>
  
  <p>So the console output is </p>
  
  <blockquote>
    <p><em>before run func = 10; after ran func =11</em></p>
  </blockquote>
  
  <p>The question is how can I just send a copy of the "object" to keep its value which equal to 10</p>
  
  <p>And if functions are always pass-by-reference, why we still need the keyword: <code>"inout"</code> </p>
  
  <p>what does difference between <code>A_plusplus(&amp;object)//[if I make the parameter to be a inout parameter]</code> and <code>A_plusplus(object)</code></p>
  
  <blockquote>
    <p>Universally, I don't want to use <code>struct</code>. Although this will solve my
    problem exactly, I do pass-by-value rarely.So I don't want program's
    copying processes slow my user's phone down :(</p>
    
    <p>And It seems conforming the <code>NSCopying</code> protocol is a good option.But
    I don't know how to implement the function: 
    <code>func copyWithZone(zone:
    NSZone)-&gt; AnyObject?</code> correctly</p>
  </blockquote>