我想在我的应用程序中显示一个ActivityIndicatorView,但是当我sync从主线程调用该方法时,应用程序崩溃并出现错误:exc_bad_instruction (code=exc_i386_invop subcode=0x0)
我正在使用xcode 8.0和swift 3
有人可以帮帮我吗?
func POST(endpoint:NSString!,body:NSString!,vc:UIViewController? = nil)->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: &self.response) as NSData!
} catch let …Run Code Online (Sandbox Code Playgroud)