Clang: There should be an attribute/macro to indicate ObjC methods will never return nil (thus imported non-optional in Swift)
| Originator: | aufflick | ||
| Number: | rdar://18346138 | Date Originated: | 16-Sep-2014 12:14 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6.0 (6A313) |
| Classification: | Enhancement | Reproducible: | Always |
Summary: Frameworks often expose methods that will verifiably never return nil. As some system frameworks do, it should be possible to annotate Objective-C methods and properties to indicate this, such that Swift will import them as regular types, not optionals. As a great extra benefit, this could mean that (once a good portion of people’s frameworks are annotated), non-annotated methods/properties could be imported as regular optionals, not assumed variables (which decreases safety, as per rdar://18119727). Steps to Reproduce: 1. Observe that some system Objective-C frameworks expose non-optional methods to Swift. 2. Attempt to use __attribute__((returns_nonnull)) to do the same. 2. Look in the headers and the Clang web pages to see how they do it, since that didn’t work. Expected Results: Expect to see some simple attribute or macro used to annotation the method. Actual Results: Observe that magical pixie dust is used to achieve the desired outcome. Notes: Magical pixie dust does not seem to be available on developer.apple.com
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!