Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 6 language mode? #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.5
// swift-tools-version:6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -15,7 +15,11 @@ let package = Package(
targets: [
.target(
name: "TinyNetworking",
dependencies: []),
dependencies: [],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.testTarget(
name: "TinyNetworkingTests",
dependencies: ["TinyNetworking"]),
Expand Down
62 changes: 0 additions & 62 deletions Sources/TinyNetworking/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,68 +220,6 @@ public struct WrongStatusCodeError: Error {
}
}

extension URLSession {
@discardableResult
/// Loads an endpoint by creating (and directly resuming) a data task.
///
/// - Parameters:
/// - e: The endpoint.
/// - onComplete: The completion handler.
/// - Returns: The data task.
public func load<A>(_ e: Endpoint<A>, onComplete: @escaping (Result<A, Error>) -> ()) -> URLSessionDataTask {
let r = e.request
let task = dataTask(with: r, completionHandler: { data, resp, err in
if let err = err {
onComplete(.failure(err))
return
}

guard let h = resp as? HTTPURLResponse else {
onComplete(.failure(UnknownError()))
return
}

guard e.expectedStatusCode(h.statusCode) else {
onComplete(.failure(WrongStatusCodeError(statusCode: h.statusCode, response: h, responseBody: data)))
return
}

onComplete(e.parse(data,resp))
})
task.resume()
return task
}
}

#if canImport(Combine)
import Combine

@available(iOS 13, macOS 10.15, watchOS 6, tvOS 13, *)
extension URLSession {
/// Returns a publisher that wraps a URL session data task for a given Endpoint.
///
/// - Parameters:
/// - e: The endpoint.
/// - Returns: The publisher of a dataTask.
public func load<A>(_ e: Endpoint<A>) -> AnyPublisher<A, Error> {
let r = e.request
return dataTaskPublisher(for: r)
.tryMap { data, resp in
guard let h = resp as? HTTPURLResponse else {
throw UnknownError()
}

guard e.expectedStatusCode(h.statusCode) else {
throw WrongStatusCodeError(statusCode: h.statusCode, response: h, responseBody: data)
}

return try e.parse(data, resp).get()
}
.eraseToAnyPublisher()
}
}
#endif

#if swift(>=5.5) && canImport(Darwin)
@available(iOS 15, macOS 12.0, watchOS 8, tvOS 15, *)
public extension URLSession {
Expand Down
7 changes: 0 additions & 7 deletions Tests/LinuxMain.swift

This file was deleted.

35 changes: 0 additions & 35 deletions Tests/TinyNetworkingTests/TinyHTTPStubURLProtocol.swift

This file was deleted.

7 changes: 1 addition & 6 deletions Tests/TinyNetworkingTests/TinyNetworkingTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@testable import TinyNetworking
import XCTest

@MainActor
final class TinyNetworkingTests: XCTestCase {
func testUrlWithoutParams() {
let url = URL(string: "http://www.example.com/example.json")!
Expand All @@ -19,10 +20,4 @@ final class TinyNetworkingTests: XCTestCase {
let endpoint = Endpoint<[String]>(json: .get, url: url, query: ["foo": "bar bar"])
XCTAssertEqual(URL(string: "http://www.example.com/example.json?abc=def&foo=bar%20bar")!, endpoint.request.url)
}

static var allTests = [
("testUrlWithoutParams", testUrlWithoutParams),
("testUrlWithParams", testUrlWithParams),
("testUrlAdditionalParams", testUrlAdditionalParams),
]
}
69 changes: 0 additions & 69 deletions Tests/TinyNetworkingTests/URLSessionIntegrationTests.swift

This file was deleted.

10 changes: 0 additions & 10 deletions Tests/TinyNetworkingTests/XCTestManifests.swift

This file was deleted.