title: Swift - how to count bytes and convert them to megabytes?
body: <p>I try to add bytes with bytes in order to get space that will be occupied by photos which i retrieve from internet.</p>
  
  <p>I have following code, it gets sizes in bytes for each id in <code>array</code> of <code>id</code></p>
  
  <pre><code>    var diskSpace:Int64 = 0
  
      for var i = 0; i &lt; array.count; i++  {
  
          let id = array[i]
  
          let urlString = "urlToFetchData"
  
          if let url = NSURL(string: urlString) {
              if let data = try? NSData(contentsOfURL: url, options: []) {
                  let json = JSON(data: data)
  
                  let size = Int64(json["size"].stringValue)
  
                  diskSpace = diskSpace + size!
  
              }
          }
  
      }
  
     var diskSpaceInMb = diskSpace / 1024 / 1024
     print("diskSpaceInMb is \(diskSpaceInMb)")
  </code></pre>
  
  <p>for example, I try to get size of three elements, which have following size in bytes (these sizes in bytes I receive in json)</p>
  
  <pre><code>3223653
  5855382
  8948976
  </code></pre>
  
  <p>when the code above is executed i receive result of</p>
  
  <pre><code>diskSpaceInMb is 8
  </code></pre>
  
  <p>which is obviously not try</p>
  
  <p>How to convert bytes to megabytes correctly ?</p>