r/iOSProgramming • u/Thatpersiankid • May 10 '23
Question Best swift network libraries
Are there any good libraries that support async/await and can handle things like form data gracefully? I want to use alamofire but thats not really an option
39
u/imhenoch May 10 '23
There’s this amazing thing called URLSession, has support for async/await and can handle form data.
0
5
u/mobinezzati May 10 '23
Most big companies don’t rely on third parties code for critical parts so try to be dominant on Urlsession
4
u/StrangeMonk May 10 '23
Just write it using system APIs, so easy. If you need stuff like retries and certificate pinning try alamofire, my friend works on it and added all the async/await code to it over a year ago.
4
u/saintmsent May 10 '23
Standard URLSession is good enough for all things networking already. Alamofire is THE third-party library if for some reason you have to use one. Why wouldn't it be an option?
1
u/redblack_ Sep 26 '23
Explain "gracefully"? And what is a good library to you?
did you encounter issues like performance, errors, encoding/decoding?
1
u/Thatpersiankid Sep 26 '23
I wanted something that supports async await easily
1
u/redblack_ Sep 26 '23
this looks easy to me (Docs):
func data(
from url: URL,
delegate: (URLSessionTaskDelegate)? = nil
) async throws -> (Data, URLResponse)
3
u/RodrigoDumont Objective-C / Swift May 10 '23
I think the official URLSession is really good option... I used it sometime ago to create this library https://github.com/RxDx/restapi that uses it (async/await), dynamically serializes the response and returns the object (that should conforms to Codable protocol).
1
u/iAlexMarr Apr 11 '24
I suggest looking at simple URLSession based wrappers. I agree that if things like multi-part and certificate pinning are not required, then there is no need to complicate it with a heavy framework. For example, now I'm using URLSessionAdapter (https://github.com/denissimon/URLSessionAdapter), and it can be used just by adding .swift files to an Xcode project, without making it a dependency
1
1
u/Shxhxxhcx May 10 '23
Stop resorting to third party libs and just learn how to code instead. This (networking) is a fundamental feature in Swift / app development
2
u/Thatpersiankid May 10 '23
URLSession doesn't natively support multipart forms. One would have to implement it themselves