我正在使用Parse来访问应用程序数据,我的目标是检查用户是否已经应用。在这种情况下在主线程上执行长操作是否正常
func buttonApplyClicked() {
if (userAlreadyApplied()==false) {
// gather data and register the user
}
}
func userAlreadyApplied() {
// executing on main thread will block
let applicant = parseQueryInstance.getFirstObject()
return applicant != nil
// or
parseQueryInstance.getFirstObjectInBackgroundWithBlock() {
// check data and return result
}
}
所以,如果使用异步调用我失去了主线程,如果我使用同步调用我得到警告,我执行长操作。
我想在主线程上执行这个操作是可以的,我想也可以在主线程中执行注册操作,我是否想好?