title: Can the non-string "property name" passed to #keyPath() be saved independently?
body: <p>I was very happy to find Swift 3's implementation of <code>#keyPath()</code>, which will eliminate typos and enforce at compile time that the key path actually exists. Much better than manually typing Strings.</p>
  
  <p><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0062-objc-keypaths.md" rel="nofollow noreferrer">https://github.com/apple/swift-evolution/blob/master/proposals/0062-objc-keypaths.md</a></p>
  
  <pre><code>class MyObject {
      @objc var myString: String = "default"
  }
  
  // Works great
  let keyPathString = #keyPath(MyObject.myString)
  </code></pre>
  
  <p>The <a href="https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Expressions.html" rel="nofollow noreferrer">Swift docs list the type</a> being passed into <code>#keyPath()</code> as a "property name".</p>
  
  <p><a href="https://i.stack.imgur.com/k9MMX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k9MMX.png" alt="&quot;property name&quot;"></a></p>
  
  <blockquote>
    <p>The property name must be a reference to a property that is available in the Objective-C runtime. At compile time, the key-path expression is replaced by a string literal.</p>
  </blockquote>
  
  <p>Is it possible to save this "property name" independently, then later pass to <code>#keyPath()</code> to create a String?</p>
  
  <pre><code>let propertyName = MyObject.myString // error. How do I save?
  let string = #keyPath(propertyName)
  </code></pre>
  
  <p>Is there any support for requiring a property name belonging to a specific Type?    </p>
  
  <pre><code>// something like this
  let typedPropertyName: MyObject.PropertyName = myString // error
  let string = #keyPath(typedPropertyName)
  </code></pre>
  
  <p>The end goal will be interacting with with APIs that require an <code>NSExpression</code> for a key path. I would like to write convenience methods that take a valid Property Name as a parameter, rather than random key path strings. Ideally, a Property Name implemented by a specific Type.</p>
  
  <pre><code>func doSomethingForSpecificTypeProperty(_ propertyName: MyObject.PropertyName) {
  
      let keyPathString = #keyPath(propertyName)
  
      let expression = NSExpression(forKeyPath: keyPathString)
  
      // ...
  }
  </code></pre>