<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I have personally filed a few bugs on this; and I definitely consider it a bug that we cannot store Any in generics for objc. There are however some problem areas that might be worth considering while fixing this bug. <div class=""><br class=""></div><div class="">1) We need to ensure this does not cause source churn - I would expect swift 4 to be source compatible with swift 5.</div><div class=""><br class=""></div><div class="">2) There are a few cases that might be a bit cagey - you claim NSCache, but would it be surprising that the boxed object having no refs gets purged? How bout NSPointerArray? </div><div class=""><br class=""></div><div class="">3) Since Foundation is likely the most impact here I think it would be useful to audit the results of this before pushing it out; specifically the Foundation internal builds so that we can make sure the things we are working on function correctly.</div><div class=""><br class=""></div><div class="">Do you have implementations in the works yet? I really think this is important for us to get in (especially before the ABI gets locked down cause it could have impact there…)<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Nov 8, 2017, at 11:49 AM, Riley Testut via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class="">Hi Swift-Evolution,<div class=""><br class=""></div><div class="">Back when SE-0057 (<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0057-importing-objc-generics.md" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0057-importing-objc-generics.md</a>) was proposed, it included the following passage:</div><div class=""><br class=""></div><div class=""><ul style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; padding-left: 2em;" class=""><li style="box-sizing: border-box;" class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">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;" class="">T : AnyObject</code>.</span></li></ul><div class="">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" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0116-id-as-any.md</a>) was accepted, which allowed for bridging <i class="">any</i> type to Objective-C, not just class types.</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Thoughts?</div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>