Backward compatible async/await for URLSession!

Overview

URLSessionBackport

Test Status

URLSessionBackport aims to make it possible to use URLSession's new async/await syntax on older OSs, namely iOS 13 or macOS 10.15 and newer. Note that Xcode 13.2 is required, as that version contains the necessary back-ported async/await libraries.

Installation

Add URLSessionBackport as a dependency in your Package.swift file to start using it. Then, add import URLSessionBackport to any file you wish to use the library in.

Please check the releases for recommended versions.

dependencies: [
    .package(url: "https://github.com/mochidev/URLSessionBackport.git", .upToNextMinor(from: "1.0.0")),
],
...
targets: [
    .target(
        name: "MyPackage",
        dependencies: [
            "URLSessionBackport",
        ]
    )
]

What is URLSessionBackport?

URLSessionBackport adds a single property to your URLSession instances: .backport. The best part? Within this namespace, URLSession's async/await methods have been magically re-implemented, allowing you access to them on iOS 13 or macOS 10.15 and newer! Additionally, the methods are automatically marked as deprecated, so they'll let you know when it's safe to remove them.

Contributing

Contribution is welcome! Please take a look at the issues already available, or start a new issue to discuss a new feature. Although guarantees can't be made regarding feature requests, PRs that fit with the goals of the project and that have been discussed before-hand are more than welcome!

Please make sure that all submissions have clean commit histories, are well documented, and thoroughly tested. Please rebase your PR before submission rather than merge in main. Linear histories are required.

You might also like...
🖼 Gallery App for Actomaton (async/await + Elm Architecture) + SwiftUI.
🖼 Gallery App for Actomaton (async/await + Elm Architecture) + SwiftUI.

🖼 Actomaton-Gallery Gallery App for Actomaton (async/await + Elm Architecture) + SwiftUI. NOTE: Most of the code are reused from Harvest-SwiftUI-Gall

⏳ Collection of Swift 5.5 async/await utility functions.

⏳ FunAsync Collection of Swift 5.5 async/await utility functions. Throw - Result conversion asyncThrowsToAsyncResult asyncResultToAsyncThrows More C

🎭 Swift async/await & Actor-powered effectful state-management framework.
🎭 Swift async/await & Actor-powered effectful state-management framework.

🎭 Actomaton 🧑‍🎤 Actor + 🤖 Automaton = 🎭 Actomaton Actomaton is Swift async/await & Actor-powered effectful state-management framework inspired by

⚡️ Lightweight full-featured Promises, Async & Await Library in Swift
⚡️ Lightweight full-featured Promises, Async & Await Library in Swift

Lightweight full-featured Promises, Async & Await Library in Swift What's this? Hydra is full-featured lightweight library which allows you to write b

Autocomplete for a text field in SwiftUI using async/await
Autocomplete for a text field in SwiftUI using async/await

Autocomplete for a text field in SwiftUI using async/await

A lightweight swift network layer with Combine, Async-Await, and a traditional completion block.

CombineNetwork A simple light-weight network library to make network requesting simpler. It supports newer techonology such as async/await as well as

AnimeListSwiftUI - Anime quote list built with MVVM Swift 5 using Async/Await

How To In SwiftUI Async/Await AnimeListSwiftUI - Anime quote list built with MVVM Swift 5 using Async/Await Clones Clubhouse - App clone built with Sw

async and await for Swift.
async and await for Swift.

async and await for Swift. Usage Beta version. New docs soon... Contribute If you have any problems or need more information, please open an issue usi

A cli program written in swift (with async/await) that removes the unnecessary parts of xcframeworks.

xctrim A cli program written in swift (with async/await) that removes the unnecessary parts of xcframeworks. Usecase Say you downloaded firebase sdk a

Prototype actor and async/await toolkit for Swift 5.5+

Prototype actor and async/await toolkit for Swift 5.5+

A web API client in Swift built using Async/Await

Web API Client A modern web API client in Swift built using Async/Await and Actors. let client = APIClient(host: "api.github.com") // Using the clien

Swift async/await OAuth 2.0 HTTP request library.

SwAuth SwAuth is an OAuth 2.0 HTTP request library written in Swift iOS 15.0+, macOS 12.0+, watchOS 8.0+, and tvOS 15.0+. Features Requirements Instal

A simple network layer for use in small iOS projects with async/await support

SimpleNetwork Intro SimpleNetwork is simple network layer for use in small projects. Swift Package Manager Note: Instructions below are for using Swif

Example project showing how to use async/await with iOS 13
Example project showing how to use async/await with iOS 13

ios13AsyncAwait Example project showing how to use async/await with iOS 13 Article This source code is a part of an article published at This Dev Brai

AsyncHTTP - Generic networking library written using Swift async/await

Generic networking library written using Swift async/await

Using async / await on iOS 13: everything you need to know
Using async / await on iOS 13: everything you need to know

Using async / await on iOS 13: everything you need to know! 🚀 Content This repository contains the code sample I've used during December 14th's lives

Hydra: Lightweight full-featured Promises, Async-Await Library in Swift

Async Functions for ECMAScript The introduction of Promises and Generators in EC

A web API client in Swift built using Async/Await

Get A modern web API client in Swift built using Async/Await and Actors. let cli

AsyncTaskKit - contains some additions to async/await Task

AsyncTaskKit This repo contains some additions to async/await Task. In general i

Comments
  • Using URLSession.backport.bytes(for:) causing crash

    Using URLSession.backport.bytes(for:) causing crash

    First at all, thanks a lot for taking the time to create a library that backports the async/await versions of URLSession to iOS 14.

    I am currently implementing some feature based on URLSession.bytes(for:) in my codebase. I still need to support iOS 14 and therefore found your library. In general the port works, but unfortunately not reliably. I often face crashes related to EXC_BAD_ACCESS or SIGABRT. When using an iOS 15 simulator, and therefore using the system provided methods the crash is not appearing,

    I already tried to debug it a little, and it always crashes within the DataAccumulator. But at random places. Sometimes when data is added to the internal buffer or sometimes when reading from it. But the place seems to be random. I assume that there are some race conditions when the data receival is ending.

    • Maybe the .success case is already causing the data accumulator to be deallocated but another continuation is still running ?
    • Or maybe some other race condition is occuring, not sure unfortunately :/

    Some examplary stack trace:

    First Example

    2022-06-20 21:03:10.358559+0200 URLSessionBackportTest[24786:502404] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed
    URLSessionBackportTest(24786,0x700007ae8000) malloc: Incorrect checksum for freed object 0x7f807c40f288: probably modified after being freed.
    Corrupt value: 0xffffffe00000000
    URLSessionBackportTest(24786,0x700007ae8000) malloc: *** set a breakpoint in malloc_error_break to debug
    URLSessionBackportTest(24786,0x700007ae8000) malloc: Incorrect checksum for freed object 0x7f807c40f288: probably modified after being freed.
    Corrupt value: 0xffffffe00000000
    CoreSimulator 802.6.1 - Device: iPhone 8 Plus (250B5764-5BFD-440B-A918-82B557B5A993) - Runtime: iOS 14.5 (18E182) - DeviceType: iPhone 8 Plus
    (lldb) 
    

    In the stack trace it can also be the seen where from the DataAccumulator this comes from:

    Screenshot 2022-06-20 at 21 32 36

    Second Example

    2022-06-20 21:36:20.604135+0200 URLSessionBackportTest[26678:539387] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed
    URLSessionBackportTest(26678,0x70000a1da000) malloc: Incorrect checksum for freed object 0x7fe7d9905d18: probably modified after being freed.
    Corrupt value: 0x2ffffffe00000000
    URLSessionBackportTest(26678,0x70000a1da000) malloc: *** set a breakpoint in malloc_error_break to debug
    URLSessionBackportTest(26678,0x70000a1da000) malloc: Incorrect checksum for freed object 0x7fe7d9905d18: probably modified after being freed.
    Corrupt value: 0x2ffffffe00000000
    CoreSimulator 802.6.1 - Device: iPhone 8 Plus (250B5764-5BFD-440B-A918-82B557B5A993) - Runtime: iOS 14.5 (18E182) - DeviceType: iPhone 8 Plus
    (lldb) 
    
    Screenshot 2022-06-20 at 21 36 29

    Third example

    Screenshot 2022-06-20 at 21 37 59

    I have also created a test repository which loads some image and also contains the kind of code I use the library with: https://github.com/alexanderwe/URLSessionBackportTest

    Any help with that is highly appreciated !

    opened by alexanderwe 1
  • Add Tests

    Add Tests

    Needs more tests to compare the esoteric cases to each other. I'm thinking of duplicating many of the tests with non-backported implementations, so if something nitty gritty changes (URL Session changes the order in which delegate methods are called, for instance), we can catch them.

    enhancement 
    opened by dimitribouniol 0
Releases(0.2.0)
  • 0.2.0(Nov 11, 2021)

    What's Changed

    • Added license by @dimitribouniol in https://github.com/mochidev/URLSessionBackport/pull/3
    • Async Bytes by @dimitribouniol in https://github.com/mochidev/URLSessionBackport/pull/1

    Hopefully with the next round of PRs (tests), I can call this a 1.0 🎉

    Full Changelog: https://github.com/mochidev/URLSessionBackport/compare/0.1.1...0.2.0

    Source code(tar.gz)
    Source code(zip)
  • 0.1.1(Nov 11, 2021)

    The actual first release 😉

    What's Changed

    • Tests Now Compile! by @dimitribouniol in https://github.com/mochidev/URLSessionBackport/pull/2

    Full Changelog: https://github.com/mochidev/URLSessionBackport/compare/0.1.0...0.1.1

    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Nov 11, 2021)

Owner
Mochi Development, Inc.
Mochi Development, Inc.
Prototype actor and async/await toolkit for Swift 5.5+

Prototype actor and async/await toolkit for Swift 5.5+

d-exclaimation 0 Feb 17, 2022
Async+ for Swift provides a simple chainable interface for your async and throwing code, similar to promises and futures

Async+ for Swift provides a simple chainable interface for your async and throwing code, similar to promises and futures. Have the best of both worlds

async_plus 132 Jan 6, 2023
Use this package in order to ease up working with Combine URLSession.

Use this package in order to ease up working with Combine URLSession. We support working with Codable for all main HTTP methods GET, POST, PUT and DELETE. We also support MultipartUpload

Daniel Mandea 1 Jan 6, 2022
macOS utility for converting fat-frameworks to SPM-compatible XCFramework with arm64-simulator support

xcframework-maker macOS utility for converting fat-frameworks to SPM-compatible XCFramework with arm64-simulator support. ?? Description make-xcframew

Dariusz Rybicki 312 Dec 22, 2022
MiniKeePass provides secure password storage on your phone that's compatible with KeePass.

MiniKeePass MiniKeePass provides secure password storage on your phone that's compatible with KeePass. View, Edit, and Create KeePass 1.x and 2.x file

null 896 Dec 14, 2022
straightforward networking and error handling with async-await and URLSession

AsyncAwaitNetworkingPlayground How To Run Just clone the project, open it and run. Some notes about AsyncAwaitNetworkingPlayground It's a straightforw

Fırat Yenidünya 17 Dec 11, 2022
🤵🏽‍♀️ Janet — A thin HTTP networking layer built on URLSession for simple, declarative endpoint specification leveraging the power of async/await.

????‍♀️ Janet — Just another networking kit — A thin HTTP networking layer built on URLSession for simple, declarative endpoint specification leveragi

Niklas Holloh 3 Sep 6, 2022
iOS 13-compatible backports of commonly used async/await-based system APIs that are only available from iOS 15 by default.

AsyncCompatibilityKit Welcome to AsyncCompatibilityKit, a lightweight Swift package that adds iOS 13-compatible backports of commonly used async/await

John Sundell 367 Jan 5, 2023
Hydra ⚡️ Lightweight full-featured Promises, Async & Await Library in Swift

Lightweight full-featured Promises, Async & Await Library in Swift What's this? Hydra is full-featured lightweight library which allows you to write b

Daniele Margutti 2k Dec 24, 2022
Fetch Multiple Rest API using Swift 5.5 Async Await with Task, TaskGroup, Continuation API

Source code for Tutorial on experimenting with Swift Async Await to fetch multiple REST API endpoints and eliminate Pyramid of Doom callback hell to improve code readability and maintanability

Alfian Losari 14 Dec 7, 2022