-[NSMapTable objectEnumerator] returns nil for empty map tables
| Originator: | prachi | ||
| Number: | rdar://19893944 | Date Originated: | |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | Reproducible: | Always |
Summary: Sending an NSMapTable -objectEnumerator returns nil for empty map tables instead of an enumerator with no objects. This is unexpected, undocumented, and crashes Swift apps because objectEnumerator is declared as follows in Swift: func objectEnumerator() -> NSEnumerator Steps to Reproduce: (See attached playground for Swift). 1. Create a new NSMapTable instance. 2. Send the instance the -objectEnumerator message before adding any objects to it. Expected Results: An NSEnumerator instance with zero objects should be returned. This is what NSDictionary and NSArray do. Actual Results: nil is returned. Version: Xcode 6.1.1/6A2008a), OS X 10.10.2/14C109 Notes: Configuration: This occurs for both iOS and OS X apps.
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!
Swift playground:
import Cocoa
var mapTable = NSMapTable.strongToStrongObjectsMapTable()
var keyEnumerator = mapTable.keyEnumerator()
var objectEnumerator = mapTable.objectEnumerator()