# Question about using @dynamicMemberLookup with enum KeyPath

**URL:** <https://forums.swift.org/t/question-about-using-dynamicmemberlookup-with-enum-keypath/50327>\
**Category:** Using Swift\
**Tags:** dynamicmemberlookup\
**Created:** [July 9, 2021, 4:27pm UTC](https://forums.swift.org/t/question-about-using-dynamicmemberlookup-with-enum-keypath/50327 "2021-07-09T16:27:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![miku1958](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/miku1958/32/11936_2.png) [@miku1958](https://forums.swift.org/u/miku1958)\
**Post date:** [July 9, 2021, 4:27pm UTC](https://forums.swift.org/t/question-about-using-dynamicmemberlookup-with-enum-keypath/50327/1 "2021-07-09T16:27:48Z")

</div>

Hi, I have an idea for adding @dynamicMemberLookup to an OptionSet and using an enum as it's dynamicMember, such as:

```swift
@dynamicMemberLookup
struct TestOption: OptionSet {
	let rawValue: UInt
	enum Options: UInt {
		case option1
		case option2
		case option3
		static let option4 = Options.option1 // add this for testing
	}
	
	static subscript(dynamicMember keyPath: KeyPath<Options.Type, Options>) -> TestOption {
		let option = Options.self[keyPath: keyPath]
		return TestOption(rawValue: 1 << option.rawValue)
	}
}

```

But it doesn't work at all, Xcode alerts me of these error:  
TestOption.option1 // Dynamic key path member lookup cannot refer to enum case 'option1'  
TestOption.option4 // Dynamic key path member lookup cannot refer to static member 'option4'

Is dynamicMemberLookup not supported in this way or was I just writing something wrong?

Thanks.

---

<div class="post-metadata">

**Author:** ![Peter-Schorn](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/peter-schorn/32/11183_2.png) [@Peter-Schorn](https://forums.swift.org/u/Peter-Schorn)\
**Post date:** [July 9, 2021, 5:40pm UTC](https://forums.swift.org/t/question-about-using-dynamicmemberlookup-with-enum-keypath/50327/2 "2021-07-09T17:40:27Z")

</div>

enum cases are static members, and static members cannot be referenced in keypaths, so what you want is not possible.

You'll have to use a string instead of a key path in the `dynamicMember` subscript.
