在Swift 4或更高版本中调用此函数时,必须传递一个'()'元组;你的意思是输入类型是'()'吗?

时间:2018-03-16 20:52:16

标签: swift swift4

我需要帮助它的代码为什么在更改Swift 3之后出现Swift 4? 5000分之89 我正在为IOS 11移动,因为我在8岁时改变了方法的所有元组 请帮助

let action: () -> Void = { [unowned self] in
    self.cameraController.takePicture { self.isTakingPicture = false }}


fileprivate func takePicture() {
        guard isBelowImageLimit() && !isTakingPicture else { return }
        isTakingPicture = true
        bottomContainer.pickerButton.isEnabled = false
        bottomContainer.stackView.startLoader()
        let action: () -> Void = { [unowned self] in
          self.cameraController.takePicture { self.isTakingPicture = false }
        }

        if configuration.collapseCollectionViewWhileShot {
          collapseGalleryView(action)
        } else {
          action()
        }
      }
    }

1 个答案:

答案 0 :(得分:0)

根据代码行

self.cameraController.takePicture { self.isTakingPicture = false }}

takePicture期待一个完成块,takePicture没有。

您可以编写方法:

fileprivate func takePicture(completion: () -> Void) {
     guard isBelowImageLimit() && !isTakingPicture else { 
       return }
     isTakingPicture = true
     bottomContainer.pickerButton.isEnabled = false
     bottomContainer.stackView.startLoader()
     let action: () -> Void = { [unowned self] in
       self.cameraController.takePicture { self.isTakingPicture = false 
     }
     }

     if configuration.collapseCollectionViewWhileShot {
      collapseGalleryView(action)
     } else {
      action()
     }
   }
  //Need to call the completion block
  completion()
}

完成块甚至需要在保护块内调用,可能带有一些布尔参数,否则“self.isTakingPicture = false”行将不会被执行。