O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Avoiding temporal coupling

Suppose that we have a code statement that is dependent on another code statement, as shown in the following code:

func sendRequest() {     let sessionConfig = URLSessionConfiguration.default     let session = URLSession(configuration: sessionConfig,                              delegate: nil,                              delegateQueue: nil)     var url: URL?     var request: URLRequest     /* First request block starts: */     url = URL(string: "https://httpbin.org/get")     request = URLRequest(url: url! as URL)     request.httpMethod = "GET"     let task = session.dataTask(with: request) {         (data: Data?, response: URLResponse?, error: Error?) -> Void in         if (error == nil) {             let statusCode = (response as! HTTPURLResponse).statusCode  print("URL Session Task Succeeded: HTTP \(statusCode)") ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required