Initial commit

This commit is contained in:
Sven Weidauer 2021-11-09 19:46:11 +01:00
commit 55229d9473
5 changed files with 68 additions and 0 deletions

7
.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

20
Package.swift Normal file
View file

@ -0,0 +1,20 @@
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "AsyncBackports",
platforms: [
.macOS(.v12),
.iOS(.v15),
.watchOS(.v8),
.tvOS(.v15),
],
products: [
.library(name: "AsyncBackports", targets: ["AsyncBackports"]),
],
targets: [
.target(name: "AsyncBackports", dependencies: []),
]
)

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# AsyncBackports
A description of this package.

View file

@ -0,0 +1,4 @@
public struct Backport<Original> {
let original: Original
}

View file

@ -0,0 +1,34 @@
import Foundation
public extension URLSession {
var backport: Backport<URLSession> { .init(original: self) }
}
public extension Backport where Original: URLSession {
/// Convenience method to load data using an URLRequest, creates and resumes an URLSessionDataTask internally.
///
/// - Parameter request: The URLRequest for which to load data.
/// - Parameter delegate: Task-specific delegate.
/// - Returns: Data and response.
@available(macOS, deprecated: 12.0, message: "No need for .backport any more")
@available(iOS, deprecated: 15.0, message: "No need for .backport any more")
@available(tvOS, deprecated: 15.0, message: "No need for .backport any more")
@available(watchOS, deprecated: 8.0, message: "No need for .backport any more")
func data(for request: URLRequest, delegate: URLSessionTaskDelegate? = nil) async throws -> (Data, URLResponse) {
return try await original.data(for: request, delegate: delegate)
}
/// Convenience method to load data using an URL, creates and resumes an URLSessionDataTask internally.
///
/// - Parameter url: The URL for which to load data.
/// - Parameter delegate: Task-specific delegate.
/// - Returns: Data and response.
@available(macOS, deprecated: 12.0, message: "No need for .backport any more")
@available(iOS, deprecated: 15.0, message: "No need for .backport any more")
@available(tvOS, deprecated: 15.0, message: "No need for .backport any more")
@available(watchOS, deprecated: 8.0, message: "No need for .backport any more")
func data(from url: URL, delegate: URLSessionTaskDelegate? = nil) async throws -> (Data, URLResponse) {
return try await original.data(from: url, delegate: delegate)
}
}