2017-10-18 45 views
0

我正在做一個asynchronous HTTP POST任務,完成時我需要將結果發送回啓動器viewcontroller。我掛鉤了完成處理程序,並且一切按預期工作。但我不能正確地申報返回變量,由於這個錯誤在任務完成時設置啓動器視圖控制器的變量

Implicit use of 'self' in closure; use 'self.' to make capture semantics explicit

   dourltask() { isValid in 
       // do something with the returned Bool 
       DispatchQueue.main.async { 
        self.spinner.isHidden=true; 
        self.spinner.stopAnimation(self) if(isValid) { 
        Error ---->  if let presenter presenting as? ViewController { 
          if(isValid) { 
           presenter.bvalue=false 
          } 
         } 
        } 
+0

'if let presenter = self.presenting as? ViewController {' –

+1

@LeoDabus謝謝。 – techno

+1

@Jack ...我打算接受你的回答......似乎你刪除了它。 – techno

回答

1

一個類型的每個實例有一個叫做自我的隱含屬性,它 是完全等同於本身的實例。您可以使用自我 屬性來引用其自身實例 方法中的當前實例。

dourltask() { isValid in 
       // do something with the returned Bool 
       DispatchQueue.main.async { 
        self.spinner.isHidden=true; 
        self.spinner.stopAnimation(self) if(isValid) { 
        if let presenter = self.presenting as? ViewController { 
          if(isValid) { 
           presenter.bvalue=false 
          } 
         } 
        } 
相關問題