Swift bridging for MCSessionDelegate treats optional URL parameter as non optional and will crash whenever MCSession calls the delegate method with a nil
Originator: | raphaelcruzeiro | ||
Number: | rdar://32591711 | Date Originated: | 2017-06-06 |
Status: | open | Resolved: | no |
Product: | Multipeer Connectivity Framework | Product Version: | |
Classification: | Bug | Reproducible: | Always |
One of the MCSessionDelegate methods has the following signature in Swift: public func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL, withError error: Error?) Note the localURL parameter being a non-nullable URL. Whenever an error occurs (e.g. connection is suddenly closed) and theres an ongoing file transfer, MSSession will call this method with a nil URL which will crash the app if the delegate was implemented in Swift. localURL needs to be made optional (interestingly though, the Swift documentation for this method says that this parameter is nil). Steps to Reproduce: Create a simple multipeer app written in swift and initiate a file transfer from one device to the other. Close either one of the apps before the transfer is completed. The app on the other device will crash. Expected Results: The delegate method should be called with a nil URL and an error object Observed Results: Due to the Swift delegate method signature not having the URL parameter optional, there will be a runtime bridging error and the app will crash Version: 10.3.2
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Marked as a dupe by apple