2017-11-13 6 views
1

최종 사용자로부터 정보를 수집하는 데 사용하는 일련의 UIViewController (팝업)가 내 앱에 있습니다. 나는에이 같은 약속을 체인 관리 :PromiseKit은 한 단계 뒤로 이동

, 예를 들어, 사용자가 다시 나는 이전 "다음"로 돌아가서 전체 흐름을 취소 할 필요가 세 번째 팝업에서 누르면
firstly { 
     return showFirstPopup() 
    } 
    .then { info1 -> Promise<Info2> in 
     dismissFirstPopup() 
     //Do sth with info1... 
     return showSecondPopup() 
    } 
    .then { info2 -> Promise<Info3> in 
     dismissSecondPopup() 
     //Do sth with info2... 
     return showThirdPopup() 
    } 
    .then { info3 -> Promise<Info4> in 
     dismissThirdPopup() 
     //Do sth with info3... 
     return showForthPopup() 
    } 
    ... 
    .catch { error in 
     //Handle any error or cancellation... 
    } 

.

기본적으로 나는 한 단계 뒤로 돌아갈 수 있어야하며 사용자가 데이터를 편집하도록하고 흐름을 계속할 수 있어야합니다.

PromiseKit에서이 작업을 수행 할 수있는 방법이 있습니까? 여기

답변

1

이것은 결국 사용을 종료 한 것입니다. 희망이 다른 사람을 도울 수 있기를 바랍니다.

func myFunc(info: Info) -> Promise<()> 
{ 
    return Promise { fulfill, reject in 

     let firstPromise = shouldShowFirstPopup ? showFirstPopup() : Promise(value: info.info1) 

     firstPromise 
     .then { info1 -> Promise<Info2> in 
      info.info1 = info1 

      if (info.shouldShowSecondPopup) { 
       return showSecondPopup() 
      } 

      return Promise(value: info.info2) 
     } 
     .then { info2 -> Promise<Info3> in 
      info.info2 = info2 
      info.shouldShowSecondPopup = false 

      if (info.shouldShowThirdPopup) { 
       return showThirdPopup() 
      } 

      return Promise(value: info.info3) 
     } 
     .then { info3 -> Promise<()> in 
      info.info3 = info3 
      info.shouldShowThirdPopup = false 

      return processEverything() 
     } 
     .then { _ ->() in 
      fulfill(()) 
     } 
     .catch { error in 
      switch error { 
       case MyErrors.backPressed(let popupType): 
        switch popupType { 
         case .firstPopup: 
         reject(MyErrors.userCanceled) 
         return 

         case .secondPopup: 
         info.shouldShowFirstPopup = true 
         info.shouldShowSecondPopup = true 

         case .thirdPopup: 
         info.shouldShowSecondPopup = true 
         info.shouldShowThirdPopup = true 

         default: 
         reject(MyErrors.defaultError(message: "Not implemented case exception")) 
         return 
        } 

        firstly { 
         return myFunc(info: info) 
        } 
        .then { _ ->() in 
         fulfill(()) 
        } 
        .catch { error2 in 
         reject(error2) 
        } 

       default: 
       reject(error) 
      } 
     } 
    } 
} 
0

내가 PromiseKit에 대해 찾을 것입니다 :

PromiseKit이에 구운 취소의 개념을 있습니다. 사용자가 무언가를 취소하면 일반적으로 약속 체인을 계속하고 싶지 않지만 오류 메시지도 표시하지 않으려합니다. 그래서 취소는 무엇입니까? 성공하지 못하고 실패하지는 않지만 오류처럼 처리해야합니다. 그 이후의 모든 핸들러를 건너 뛰어야합니다. PromiseKit은 취소를 특별한 종류의 오류로 구체화합니다.

이렇게하면 모든 후속 처리기를 건너 뜁니다. 다음은이 정보를 찾은 링크입니다. Promise Kit

+0

감사합니다.하지만 흐름을 취소하고 싶지는 않습니다. 한 걸음 뒤로 물러 설 수 있어야합니다. 나는 나의 초기 질문에서 내가 분명하지 않다는 것을 깨달았다. 나는 그것을 지금 새롭게했다. – Diana