URLSession.DataTaskPublisher
負責透過 URL 到網路抓資料的 Publisher。
Last updated
Was this helpful?
負責透過 URL 到網路抓資料的 Publisher。
Last updated
Was this helpful?
> >
⭐
下面的範例示範如何從網路擷取 JSON 資料,然後轉為自己的 Swift 型別: 👉 - Convert Incoming Raw Data to Your Types
暫時的錯誤可用 .retry(_:) 處理。
無法排除的錯誤可用 .catch(_:) 與 .replaceError(with:) 處理
⚠️ 注意:
URL session starts loading data as soon as the URLSession.DataTaskPublisher has unsatisfied demand from a downstream subscriber. In this case, that happens when the first sink subscriber attaches.
If you need extra time to attach other subscribers, use .makeConnectable() to wrap the Publishers.Share publisher with a ConnectablePublisher.
After connecting all subscribers, call .connect() on the connectable publisher to allow the data load to begin.