Swift NS* optional type audit. Crashing on application:openURL:sourceApplication:annotation
| Originator: | SJ.Randazzo | ||
| Number: | rdar://18319238 | Date Originated: | 09/12/14 |
| Status: | open | Resolved: | no |
| Product: | iOS SDK | Product Version: | Xcode 6GM |
| Classification: | Crash/Swift Audit | Reproducible: | Always |
Summary: When using a swift based AppDelegate in an app that 1) implements application:openURL:sourceApplication:annotation 2) is launched via an extension (today extension) the app will crash 100% of the time due to the value of sourceApplicaiton being `nil`. The swift method signature does not declare sourceApplication as optional, thus causing a crash Steps to Reproduce: 1. Create an app in swift 2. In AppDelegate.swift, implement `application:openURL:sourceApplication:annotation`, return true or false (does not matter) 3. Provide a URL scheme to your app 3. Implement a "today extension" that launches your app with the URLscheme 4. Observe that upon launching, you crash with a system-level stack trace indicating an attempt to call `application:openURL:sourceApplication:annotation` which fails because sourceApplication is nil Expected Results: A sourceApplication should never be nil, or `sourceApplication` should be `sourceApplication?` Actual Results: sourceApplication is nil resulting in a crash. Version: Version 6.0 (6A313), any iOS (7+8) Notes: Temporary workaround: Use an objective-c AppDelegate.h/m to resolve the issue Configuration: Xcode 6GM, swift
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!