Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

swift concurrency datatask before ios 15

extension URLSession {

    func data(request: URLRequest) async throws -> (Data, URLResponse) {
        if #available(iOS 15.0, *) {
            return try await data(for: request)
        } else {
            return try await withCheckedThrowingContinuation { continuation in
                let task = self.dataTask(with: request) { data, response, error in
                    guard let data = data, let response = response else {
                        let error = error ?? URLError(.badServerResponse)
                        return continuation.resume(throwing: error)
                    }

                    continuation.resume(returning: (data, response))
                }

                task.resume()
            }
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Swift :: change multiplier programactlilly ios swift 
Swift :: do something when your HTTP response finishes. swift 
Swift :: Function Return Types in swift 
Swift :: swift constraints 
Swift :: Blinking effect on UILabel 
Swift :: Nested Loops in Swift 
Swift :: how request prefix of string in swift 
Swift :: swift uitextfield only numbers keyboard lock programmatically 
Swift :: Swift Labeled Statement with continue 
Swift :: Swift Add Elements to a Set 
Swift :: Swift Fatal error when accessing a null unwrapped optional 
Swift :: xcode enable a button after a text field is filled 
Swift :: Swift Nested for Loop 
Swift :: didselectrowatindexpath not called swift 
Ruby :: how to match email in regex in ruby 
Ruby :: ruby raise error 
Ruby :: rails validate uniqueness 
Ruby :: ruby get substring between two characters 
Ruby :: ruby file write 
Ruby :: substring replace in ruby 
Ruby :: rails foreach 
Ruby :: rails order 
Ruby :: rails array sort 
Ruby :: how to remove nested array brackets ruby 
Ruby :: open url in ruby 
Ruby :: see migration history rails 
Ruby :: ruby rails find data field type 
Ruby :: infinite loop ruby 
Ruby :: rails automatically downcase on create 
Ruby :: ruby name parameters 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =