Enhancement Request: Annotations in Obj-C headers for types within collections
| Originator: | CharlesJS | ||
| Number: | rdar://20118084 | Date Originated: | |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | Reproducible: |
Summary: This enhancement request is for an annotation syntax for Objective-C headers which can let Swift know what type is contained within collection types such as NSArray, NSDictionary, or NSSet. Something like: - (__collection_of(NSString *) NSArray *)arrayOfStrings; or: - (__collection_of(NSString *, NSNumber *) NSDictionary *)dictionaryOfStringsToNumbers; or: - (void)getASetOfStrings:(__collection_of(NSString *) NSSet * __autoreleasing *)setOfStringsPtr; This would allow Swift clients to, for example, see a returned array as a [String] instead of always as an [AnyObject]. This would enhance interoperability with Swift, particularly in frameworks, improving readability while reducing awkward casting. In this way, it would be similar to the great help provided by the nullability attributes introduced in Xcode 6.3, and would reduce a lot of confusion caused by things like the phenomenon noticed in this thread: http://lists.apple.com/archives/cocoa-dev/2015/Mar/msg00170.html Steps to Reproduce: 1. Make an Objective-C framework with a method in it that returns a collection type like NSArray or NSSet. 2. Try to use this method from Swift. Notice that the awkwardness of needing a cast. Expected Results: If an Objective-C method returns an NSArray which the framework author knows will always contain only strings, then there should be a way to annotate it such that Swift will know that the array will contain strings. Actual Results: Objective-C methods returning collections like NSArray are always assumed by Swift to contain AnyObject, which makes them harder to work with than they need to be. Version: Xcode 6D532l Notes: Configuration: Attachments:
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!