-setByAddingObject: converts toll-free bridged CFSetRefs to NSSets
Originator: | heath.borders | ||
Number: | rdar://28458772 | Date Originated: | 23-Sep-2016 07:44 PM |
Status: | Closed | Resolved: | |
Product: | Documentation | Product Version: | 8.0 |
Classification: | Serious Bug | Reproducible: | Always |
Summary: https://developer.apple.com/reference/foundation/nsset/1416316-setbyaddingobject?language=objc doesn't mention that when you call -[NSSet setByAddingObject:] on a toll-free bridged CFSetRef, the returned NSSet isn't a toll-free bridged CFSetRef. As a result, the returned NSSet may have different behavior, and thus may contain fewer objects. I demonstrate this behavior in https://gist.github.com/hborders/8aa94a3f2b69b0f0890aecd96cc2f1f1 Steps to Reproduce: View the documentation: https://developer.apple.com/reference/foundation/nsset/1416316-setbyaddingobject?language=objc https://developer.apple.com/library/content/documentation/General/Conceptual/CocoaEncyclopedia/Toll-FreeBridgin/Toll-FreeBridgin.html#//apple_ref/doc/uid/TP40010810-CH2 This behavior isn't mentioned Expected Results: The behavior shown in https://gist.github.com/hborders/8aa94a3f2b69b0f0890aecd96cc2f1f1 should be mentioned somewhere Actual Results: The behavior shown in https://gist.github.com/hborders/8aa94a3f2b69b0f0890aecd96cc2f1f1 is not mentioned anywhere
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Apple closed it and said the documentation is clear. I disagree, but you can't fight city hall.
This is a follow-up to Bug ID# 28458772.
Engineering has provided the following feedback regarding this issue:
This is expected behavior. The documentation notes that the method returns a new NSSet, which should not be expected to share any behavior defined by a toll-free bridged receiver, just like any other Foundation collection method that returns a new array, set, or dictionary.
To avoid any difference in behavior, you can create a CFMutableSet and call CFSetAddValue to add values before the collection crosses the CF-NS barrier.