Swift: String to function and vice versa
| Originator: | thebuckley | ||
| Number: | rdar://17141206 | Date Originated: | 03-Jun-2014 10:39 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | New Feature | Reproducible: | N/A |
Swift objects that inherit from Objective-C objects can make use of NSSelectorFromString, but pure-Swift objects cannot. Since Swift functions are strongly-typed, a Swift-native NSSelectorFromString would need to take additional arguments for return and parameter types. At the worst, that information would need to be encoded in the string. The reverse (function to string) would also be useful for debugging. There are probably multiple use cases for this, but for me, this functionality is useful for implementing a remote procedure interface. The client sends string messages to the server, and the server decides which function to call based on the message (this is done in a secure way). There are thousands of these messages, and putting them in a dictionary takes too much memory, and a massive if-else statement takes too long to execute. In Objective-C, NSSelectorFromString and NSInvocation have been fast and memory efficient.
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!