2

Given the following playground:

import Foundation

let config = URLSessionConfiguration.default

let session = URLSession(configuration: config)

let eq = config == session.configuration

If you run the playground in Xcode 9.4.1, eq evaluates to true. In Xcode 10.0 eq evaluates to false. I took a look at Xcode 10 release notes and the source for URLSession and I'm not sure what caused the change. It broke one of my tests and I'm scratching my head as to why this broke. Any ideas?

Edit: I get that == is just testing the pointers and URLSessionConfiguration is copied on initialization. I'm more interested in the fact that it evaluates to true in Xcode 9.4.1, which seems to be incorrect. And the fact that it changes in Xcode 10.

jscs
  • 63,694
  • 13
  • 151
  • 195
afbrandt
  • 39
  • 5

1 Answers1

1

URLSession is copying the configuration object instead of just storing it. Since it's a class, == will only return true if the two references are to the same object, which is no longer the case after it's been copied.

EmilioPelaez
  • 18,758
  • 6
  • 46
  • 50
  • Thanks for the answer. I updated my question with details on the information I'm after – afbrandt Mar 13 '19 at 18:24
  • If `URLSessionConfiguration` does not have a customized `isEqual(_:)` that compares properties, then the change is presumably that the configuration was _not_ copied in the SDK shipped with Xcode 9, but _is_ in the SDK from Xcode 10. – jscs Mar 13 '19 at 18:30