title: DispatchQueue.main.sync returning exc_bad_instruction Swift 3
body: <p>I want to display an ActivityIndicatorView in my app, but when I call the <code>sync</code> method from the main thread, the app crashes with the error: <code>exc_bad_instruction (code=exc_i386_invop subcode=0x0)</code>
  I'm using xcode 8.0 and swift 3</p>
  
  <p>Can someone please help me?</p>
  
  <pre><code> func POST(endpoint:NSString!,body:NSString!,vc:UIViewController? = nil)-&gt;NetworkResult{
      let result = NetworkResult()
      DispatchQueue.main.sync {
          self.displayActivityIndicator(viewController: vc)
      }
      let urlStr = self.url.appending(endpoint as String).appending(self.getHashAutenticacao() as String)
      print(urlStr)
      let request = NSMutableURLRequest(url: URL(string: urlStr)!, cachePolicy: NSURLRequest.CachePolicy.reloadIgnoringLocalCacheData, timeoutInterval: 20)
      print(request.debugDescription)
      request.setValue("application/json", forHTTPHeaderField: "Accept")
      request.setValue("application/json", forHTTPHeaderField: "Content-Type")
      request.httpMethod = "POST"
      request.httpBody = body.data(using: String.Encoding.utf8.rawValue, allowLossyConversion: true)
  
      // send the request
      var data: NSData!
      do {
          data = try NSURLConnection.sendSynchronousRequest(request as URLRequest, returning: &amp;self.response) as NSData!
      } catch let error1 as NSError {
          self.error = error1
          data = nil
      }
      if let httpResponse = self.response as? HTTPURLResponse {
          result.resultCode = httpResponse.statusCode
  
          if httpResponse.statusCode == 200{
              if data != nil{
                  if data.length &gt; 0{
                      let json = (try! JSONSerialization.jsonObject(with: data as Data, options: JSONSerialization.ReadingOptions.mutableContainers))
                      if let jsonArray:NSArray = json as? NSArray{
                          result.data = jsonArray
                      }else{
                          if let jsonDict:NSDictionary = json as? NSDictionary{
                              result.data = [jsonDict]
                          }
                      }
                  }
              }
          }
      }else {
          result.message = self.error!.debugDescription as NSString?
      }
  
      DispatchQueue.main.sync {
          self.hideActivityIndicator(viewController: vc)
      }
      return result
  }
  </code></pre>