티스토리 뷰

"Domain=NSURLErrorDomain Code=-999 "cancelled"" 에러가 계속되어서 엄청 스트레스 받았는데..(처음에는 헤더 문제인줄 알았다)

 

    private var cancellable: AnyCancellable? // 이렇게 작성해줘야함!!!!
    let m = buildHomeModel(customerId: "CUSTOMER000000000017")

    // Create a DataTaskPublisher
    let postUserPublisher = try! postBuildHome(body: m)

    // Use the sink Subscriber to complete the Publisher -> Subscriber pipeline
    cancellable = postUserPublisher.sink(receiveCompletion: { completion in
      switch completion {
      case let .failure(error):
        print("failed!!!!!!!!")
        print(error)
      case .finished:
        print("DONE - postUserPublisher")
      }
    }, receiveValue: { data, response in
      if let string = String(data: data, encoding: .utf8) {
        print(string)
      }
    })
  }

 

cancellable을 저장 안하면 지워져서 그런거였다

 

let cancellable ~ 도 안됨..

지역변수로 설정된 cancellable만 가능하다!!!!!!!!

 

 

The sink modifier returns an AnyCancellable. 32 When the AnyCancellable is destroyed, it cancels the subscription. In your example, you're not storing the AnyCancellable, so it is destroyed immediately, cancelling the subscription immediately.

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함