Xcode 6.1: Identify idiom for defining constants for button numbers in modals and other Ints

Originator:kusterer
Number:rdar://18700423 Date Originated:18-Oct-2014 10:01 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6.1 (6A1042b)
Classification:Enhancement Reproducible:Always
 
When using runModalForWindow() in Swift, one has to pass a constant (which one would traditionally define as an enum) through stopModalWithCode(), then turn back into the constant. This requires use of rawValue and fromRawValue(), which makes the code much less readable.

 Would be appreciated if you could come up with and communicate the right idiom to use in this case. I can see several solutions:

1) Templatize runModalForWindow() and stopModalWithCode() for Swift, so one can specify the enum that it should be when calling it.
2) Allow definition of “auto-downcasting” enums that transparently do the rawValue magic when assigned to/from Ints.
3) Extract modal panel behaviour into a separate, templatized class that one would use instead of the Int-based method in NSApplication

A similar issue also exists with view tags and menu item tags. Would be perfect if you found an idiom that worked for those as well.

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!