Swift: Add proper reflection and/or introspection functionality

Originator:adrian.kashivskyy
Number:rdar://18017381 Date Originated:14-Aug-2014 01:23 PM
Status:Dupe/17177549/Open Resolved:No
Product:Developer Tools Product Version:Xcode 6.0 Beta 5 (6A279r)
Classification:Enhancement Reproducible:Not Applicable
 
Summary:
In Objective-C, it is fairly easy to introspect a class – its name, properties, ivars and methods. It is also easy to conditionally instantiate a class, name of which is stored in a variable. An example of that would be UINavigationController's initWithNavigationBarClass, which allows for run-time substitution of the bar being used.

I am trying to create a business app, in which I dynamically instantiate a different view controller classes, based on the current locale's country (every country has its own rules and custom requirements). This kind of functionality would be very easy to implement in Objective-C, but impossible in Swift.

Another use of reflection would be when creating an automatic mapping functionality, which would inspect a given class and create a JSON representation of an instance (with small use of value transformers). Again – possible in Objective-C, not even imaginable in Swift.

I understand that you, Swift engineers, don't necessarily want to implement all features of Objective-C in Swift "just because they exist", but reflection and introspection is an important part of all major modern programming languages, by which Swift was inspired: Ruby, Python, Haskell, C# and, of course, Objective-C.

I know it's too late for it to be included in Swift 1.0, but please consider implementing this feature when developing the next version of the language.

Steps to Reproduce:
n/a

Expected Results:
n/a

Actual Results:
n/a

Version:
Feature is not yet available as of Xcode 6.0 Beta 5 (6A279r)

Notes:
n/a

Configuration:
n/a

Attachments:

--- 19-Aug-2014 00:48 AM / ADR

Engineering has determined that your bug report is a duplicate of another issue and will be closed.

17177549

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!