mirror of
https://github.com/apple/swift.git
synced 2026-06-27 12:25:55 +02:00
7c9d53a0a0
ns_error_domain can now be used to communicate with the ClangImporter when an enum has an associated error domain string. In this case, when we import it as a Swift enum, we can also synthesize a conformance to _BridgedNSError. This allows the creation of something like NS_ERROR_ENUM, in which the developer can declare an enum for the purposes of error handling. Adds Sema and executable tests demonstrating this funcionality. In order for the imported ns_error_domain bridging to work, we have to at some point forcibly pull in a _BridgedNSError conformance, as one will not be pulled in normally. This is a problem, and is explicitly signaled in the provided test case
14 lines
389 B
Objective-C
14 lines
389 B
Objective-C
#define NS_ERROR_ENUM(_type, _name, _domain) \
|
|
enum _name : _type _name; \
|
|
enum __attribute__((ns_error_domain(_domain))) _name : _type
|
|
|
|
@class NSString;
|
|
extern NSString *const TestErrorDomain;
|
|
typedef NS_ERROR_ENUM(int, TestError, TestErrorDomain) {
|
|
TENone,
|
|
TEOne,
|
|
TETwo,
|
|
};
|
|
|
|
TestError getErr();
|