> On Aug 5, 2015, at 16:38 , Charles Srstka <[email protected]> wrote:
> 
> On Aug 5, 2015, at 6:22 PM, Rick Mann <[email protected]> wrote:
>> 
>> I'd like to be able to write code like this:
>> 
>> enum MyNotifications : String {
>>    case Note1                = "note1"
>>    case Note2                = "note2"
>> }
>> 
>> let nc = NSNotificationCenter.defaultCenter()
>> nc.postNotificationName(MyNotifications.Note1, nil)
>> 
>> But Swift (2.0) doesn't let me do that. Is it possible to write an extension 
>> method to NSNotificationCenter that accepts "any enum derived from String" 
>> (or that's convertible to String, or something like that)? e.g.:
>> 
>>    func postNotification(inName : enum:String)
>> 
>> I tried doing this: http://pastebin.com/kXLEHu8f
>> 
>> But it gets multiple errors, as you can see.
>> 
>> Is there an elegant way to do this? Seems counter-intuitive that I can't 
>> pass a derived enum in place of an ancestral type.
> 
> AFAIK there’s no way to do exactly what you’re asking for, but you could put 
> a post() method on the enum itself.

Well, that kinda works, for a single enum, but I can't derive an enum from that 
because I run into this when I subclass an enum.

playground28.swift:26:16: error: raw type 'Notes' is not convertible from any 
literal
enum MyNotes : Notes
               ^
playground28.swift:26:6: error: type 'MyNotes' does not conform to protocol 
'RawRepresentable'
enum MyNotes : Notes
     ^
Swift.RawRepresentable:11:13: note: protocol requires nested type 'RawValue'
  typealias RawValue



-- 
Rick Mann
[email protected]



_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to