我如何检查函数是否被调用?我已经创建了一个函数来查看是否完成了这样的级别:
createType
当第一级被击败时,我调用函数levelOneCompleted()。
然后场景进入另一个场景。正是在这个场景我想检查函数是否被调用。我想我可以做一些“如果声明”。
kotlin.reflect.full
最好的解决方法是什么?
答案 0 :(得分:4)
在for a, b in dicta.items():
for c, d in b.items():
print "opponent 1: ", c
print "opponent 2: ", d
内设置一个布尔标志true
:
levelOneCompleted()
后来......
var isLevelOneCompleted = false
func levelOneCompleted(){
// do things...
isLevelOneCompleted = true
}
答案 1 :(得分:2)
Swift 3& Xcode 8.3.2
这有两个技巧,这是代码:
// Async operation
func levelOneCompleted(completion: (_ completed: Bool) -> Void) {
// do your function here
completion(true)
}
// Here is how to use it
// than u can declare this in viewDidLoad or viewDidAppear, everywhere you name it
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// this is async operation
levelOneCompleted { (completed) in
if completed {
print("levelOneCompleted is complete")
// do something if levelOneCompleted is complete
DispatchQueue.main.async {
// Update your UI
}
} else {
print("levelOneCompleted is not completee")
// do something if levelOneCompleted is not complete
DispatchQueue.main.async {
// Update your UI or show an alert
}
}
}
}
// Or u can use this code too, and this is Sync operation
var isLevelTwoCompleted: Bool = false
func levelOneCompleted() {
// do your function here
isLevelTwoCompleted = true
}
// to check it u can put this function everywhere you need it
if isLevelTwoCompleted {
//do something if level two is complete
} else {
//do something if level two is not complete
}