Provide a way to convert a Swift expression to its string representation (e.g. for assertions)
| Originator: | jeffreywear | ||
| Number: | rdar://17239947 | Date Originated: | 06.09.2014 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6.0 (6A215I) |
| Classification: | UI/Usability | Reproducible: | N/A |
Summary:
In C, the preprocessor can be used to retrieve the string representation of an expression. For instance, before the C `assert` macro aborts, it prints the expression that failed to be true:
#define assert(e) \
((void) ((e) ? ((void)0) : __assert (#e, __FILE__, __LINE__)))
#define __assert(e, file, line) \
((void)printf ("%s:%u: failed assertion `%s'\n", file, line, e), abort())
assert(15 < 14);
// prints '...failed assertion '15 < 14'
This is very useful in logging the context of an exception, both in production as well as in testing (the XCTest unit test assertion macros are written similarly).
However, in Swift, assertions lack this information: `assert(15 <14)` prints only "XCTestOutputBarrierassertion failed...". This will not be helpful in log messages. Please add a way to retrieve the string representation of an exception for use in assertions.
Steps to Reproduce:
Expected Results:
Actual Results:
Version:
Xcode 6.0 (6A215I)
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!