<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">Hi Swift-Evolution,<div><br></div><div>Back when SE-0057 (<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0057-importing-objc-generics.md">https://github.com/apple/swift-evolution/blob/master/proposals/0057-importing-objc-generics.md</a>) was proposed, it included the following passage:</div><div><br></div><div><ul style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; padding-left: 2em;"><li style="box-sizing: border-box;"><span style="background-color: rgba(255, 255, 255, 0);">The generic type parameters in Swift will always be class-bound, i.e., the generic class will have the requirement <code style="box-sizing: border-box; padding: 0.2em 0px; margin: 0px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">T : AnyObject</code>.</span></li></ul><div>This made sense at the time, since Swift <-> Objective-C interoperability was only possible with class types (AnyObject). However, several months after SE-0057 was accepted, SE-0116 (<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0116-id-as-any.md">https://github.com/apple/swift-evolution/blob/master/proposals/0116-id-as-any.md</a>) was accepted, which allowed for bridging <i>any</i> type to Objective-C, not just class types.</div><div><br></div><div>This greatly improved interoperability between Swift and Objective-C code, but the AnyObject restriction on Objective-C generics remained. This issue is especially apparent when using lesser-known Objective-C collection types such as NSCache, where it may make sense to store value types or use value types as the keys, but the compiler does not allow it.</div></div><div><br></div><div>I propose that this restriction is lifted, and that generic Objective-C parameters are no longer restricted to conforming to AnyObject. I’m assuming this is not as straightforward as it might seem at first to implement, but I think the benefits would make the effort worth it, since this seems like an overlooked case and not intentionally kept this way.</div><div><br></div><div>Thoughts?</div></body></html>