> On Jul 17, 2017, at 9:04 AM, Manfred Schubert <d...@schubert-it.com> wrote:
> 
> 
>> Am 17.07.2017 um 17:47 schrieb Joe Groff <jgr...@apple.com>:
>> 
>> Yeah, this is the intended use pattern for these namespaced constant. You 
>> don't need the `rawValue:` label, though:
>> 
>> extension NSImage.Name {
>> static let myImage = Name("myImage")
>> }
> 
> It would be possible to do the same thing as an extension to String without 
> making the default/simple case more complicated. So I would have said this is 
> overkill, but I'm fine with it.

By making it a separate type, though, it lets you define constants without 
polluting String's namespace, and lets the type system prevent typos or 
accidental misuse of a name.

> 
> What remains is the question whether it is possible to create NSBindingNames 
> in a safe way, like from #selector().

If you want to ensure that the string value corresponds to a declaration, maybe 
you could use #keyPath, which ought to be interchangeable with a string literal 
but checked by the compiler.

-Joe
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to