Skip to content

Commit

Permalink
Readme updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedem committed Sep 23, 2024
1 parent 05e3c4c commit eb1158c
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,16 @@ let filtered = values.remove(.intValue)
### Notes and Limitations

#### Access Control
If an enum declaration has a `public` access control specifier, the `CaseLabel` type and the `caseLabel` property are also declared as public.
The added code for `CaseLabel` and `caseLabel` use a `public` access level even when the extended enum itself has a `private` access level.

However, Swift macros cannot detect when an enum receives the access control of an extension:
The automatically added protocol conformance to `CaseIterable` does not work if the enumeration is private and is itself declared in a private namespace.
The following code will therefore not compile:
```swift
public extension MyType {
private extension Namespace {
@CaseLabeled
enum MyEnum {
case .intValue(Int)
}
}
```

Such declarations lead to a compiler error, as `CaseLabel` and `caseLabel` are declared by the macro without access control and are therefore not public, unlike the enum itself.

As a workaround, the access control should not be specified on public extensions, but always on the enum itself:
```swift
extension MyType {
@CaseLabeled
public enum MyEnum {
case .intValue(Int)
private enum MyEnum: Hashable {
case intValue(Int)
case stringValue(string: String)
}
}
```

0 comments on commit eb1158c

Please sign in to comment.