Swift 4 Argument传递给不带参数的调用

时间:2018-03-27 09:02:01

标签: swift error-handling closures

我尝试通过private func executeRefreshTokenRequest(_ completion: @escaping () throws -> Void) { DispatchQueue.global(qos: .userInitiated).sync { guard let refreshToken = currentRefreshToken else { completion({ throw RefreshTokenError.notFounded }) // Argument passed to call that takes no arguments } var refreshTokenUrlRequest:CustomURLRequest do { refreshTokenUrlRequest = try AuthService.refresh(token: refreshToken).doUrlRequest() } catch (let error) { completion({ throw UrlRequest.notDone }) // Argument passed to call that takes no arguments } execute(refreshTokenUrlRequest, PlaceToken.self) { [weak self] (placeToken, error) in if error != nil { self?.cancelAllRequests() NotificationCenter.default.post(name: Notification.Name("AuthorizationFail"), object: nil) } else { Cache.currentAuthToken = placeToken } completion() } } 进行错误处理。 当我调用完成时,我得到编译器错误" 参数传递给不带参数的调用"。我该如何修复我的代码?

public void openFragment(MyCustomFragment fragment, boolean isDialog,
                         FragmentAnimationType animationType) {
    mStackCountAfterExternalIntent++;
    FragmentManager childFragmentManager = mFragmentAdapter.getItem(mActiveTab)
            .getChildFragmentManager();
    try {
        FragmentTransaction fragmentTransaction = childFragmentManager.beginTransaction();
            if (animationType != null) {
                fragmentTransaction.setCustomAnimations(animationType.enterAnimation, 0,
                        0, animationType.exitAnimation);
            }
            fragmentTransaction.replace(R.id.child_fragment_root, fragment);
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commitAllowingStateLoss();
            if (childFragmentManager.getBackStackEntryCount() > 0) {
                FragmentManager fragmentManager = mFragmentAdapter.getItem(mActiveTab)
                        .getChildFragmentManager();
                MyCustomFragment fragmentToHide = (MyCustomFragment) fragmentManager.
                        getFragments().get(fragmentManager.getBackStackEntryCount() - 1);
            }
        System.gc();
        fragment.onVisible(true);
    } catch (Exception e) {
        App.getInstance().restartApp(mLastIntent, false);
    }
}

0 个答案:

没有答案