0
我想在GameViewController中發生事件時,在View Controller中做一些事情。無法指定'()'類型的值來鍵入'CallbackBlock!'
所以這是我做的
在GameViewController
typealias CallbackBlock =() -> Void
public class GameController {
var onAnagramSolved : CallbackBlock!
func inSomeMethod(){
self.onAnagramSolved()
}
}
在視圖控制器
public class ViewController: UIViewController {
var gameController: GameController!
public override func loadView() {
super.loadView()
gameController = GameController()
}
override public func viewDidLoad() {
super.viewDidLoad()
// This is where I get the error (which is the title)
gameController.onAnagramSolved = self.showLevelMenu()
}
func showLevelMenu(){
// A method showing UIAlertController
}
但後來我得到的錯誤說
Cannot assign a value of type '()' to type 'CallbackBlock!'
其在斯威夫特3.
感謝很多人!你救了我的一天! – Aryan