Skip to content

Commit 7bd81e5

Browse files
committed
Implements combine approach in Simple Networking page
1 parent 5839cf0 commit 7bd81e5

File tree

1 file changed

+7
-1
lines changed
  • Combine.playground/Pages/Simple Networking.xcplaygroundpage

1 file changed

+7
-1
lines changed

Combine.playground/Pages/Simple Networking.xcplaygroundpage/Contents.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ func fetchL<T: Decodable>(_ url: URL,
2727

2828
// MARK: - Combine approach
2929

30-
30+
func fetch<T: Decodable>(_ url: URL) -> AnyPublisher<T, Error> {
31+
URLSession.shared.dataTaskPublisher(for: url)
32+
.tryMap({ result in
33+
return try JSONDecoder().decode(T.self, from: result.data)
34+
})
35+
.eraseToAnyPublisher()
36+
}

0 commit comments

Comments
 (0)