Swift needs something to replace the preprocessor
Originator: | dave | ||
Number: | rdar://17170702 | Date Originated: | 05-Jun-2014 02:30 AM |
Status: | Open | Resolved: | |
Product: | Developer Tools | Product Version: | Xcode 6 Beta 1 (6A215l) |
Classification: | Enhancement | Reproducible: | N/A |
Summary: I think there needs to be something to replace the preprocessor we have in Objective-C. There seems to be no way to create macros in Swift. For example, in Objective-C we would add this to our .pch file: #define DLog(...) NSLog(@"%s(%p) %@", __PRETTY_FUNCTION__, self, [NSString stringWithFormat:__VA_ARGS__]) Then in our methods, call: DLog(@"Something happened"); The preprocessor would substitute the above define into the code, so that the __PRETTY_FUNCTION__ would contain the correct function information. Swift has __FUNCTION__, __LINE__, __FILE__ but no way for us to use them indirectly in our debug logging calls. It would also be great if __FUNCTION__ or __PRETTY_FUNCTION__ gave us the unmangled function name. Steps to Reproduce: Expected Results: Actual Results: Version: Xcode 6 Beta 1 (6A215l) 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!
I've found a workaround to part of this problem. By setting FUNCTION as a default value in a function parameter, we're able to get the correct value. See a library I've released using this here: https://github.com/DaveWoodCom/XCGLogger
A preprocessor would still be a handy tool though.