티스토리 뷰
"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.
'macOS, iOS' 카테고리의 다른 글
[iOS] .ds_store파일? (0) | 2021.02.11 |
---|---|
[iOS] lazy variable (0) | 2021.02.10 |
[iOS] URLRequest 만드는법 (0) | 2021.02.10 |
[iOS] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. (0) | 2021.02.10 |
[iOS] 카카오 간편로그인 (0) | 2021.02.09 |