On Jul 7, 2015, at 00:02 , Rick Mann <rm...@latencyzero.com> wrote: > > I want to implement some support for HTTP Headers in enums, such that I can > write this: > > extension > NSMutableURLRequest > { > func > set(inHeader : String, _ inVal : String) > { > self.setValue(inVal.rawValue, forHTTPHeaderField: > inHeader.rawValue()) > } > } > > and then call it like this: > > req.set(.ContentType, .JSON) > req.set(.ContentType, "some other type") >
Like this: > extension NSMutableURLRequest > { > func set<T, U where T: RawRepresentable, T.RawValue == String, U: > RawRepresentable, U.RawValue == String> (inHeader : T, _ inVal : U) > { > self.setValue (inVal.rawValue, forHTTPHeaderField: > inHeader.rawValue) > } > > } At least, that compiles in a playground. As you say, overloading should work for pure String values of the second parameter. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com