[swift-evolution] [swift-evolution-announce] [Review] SE-0125: Remove NonObjectiveCBase and isUniquelyReferenced

Arnold Schwaighofer aschwaighofer at apple.com
Wed Jul 20 07:59:25 CDT 2016


> On Jul 20, 2016, at 3:13 AM, Brent Royal-Gordon <brent at architechies.com> wrote:
> 
>> On Jul 19, 2016, at 11:06 PM, Dmitri Gribenko via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> - I find it a little strange to see a mention of Objective-C, and a
>> negation in `isUniquelyReferencedNonObjC`.  For example, if we get C++
>> import, would we need to rename it to
>> `isUniquelyReferencedNonObjCAndNonCXX`?  I think that is the issue
>> with negation.  If we want to emphasize that the API will work only
>> with Swift types, we can do something
>> `isUniquelyReferencedSwiftReference`.  But I would probably suggest
>> that we just go with just `isUniquelyReferenced` and mention the
>> Swift-only requirement in the documentation.
> 
> I agree.
> 
> What is the reason that isUniquelyReferenced(_:) doesn't work with Objective-C? It doesn't seem like it'd be difficult to implement—you'd either call -retainCount, or get it from the Objective-C runtime somehow, and then test it against 1—so I assume there's a reason we don’t


Also, see my answer to Dmitri.

isUniquelyReferencedNonObjC checks that the object is a uniquely referenced swift only class. It works on non- at objc classes but will return false: The API will work for @objc-classes but return false.

The reason for this combination is data structures like Array which might hold an objc class which is not mutable. On a mutating operation you check is it uniquely reference and a swift class - if the answer is yes and you have enough storage you store to the current instance. (You can’t store to an NSArray for example, you would have to check it was a NSMutableArray, etc …)


> I ask because knowing that may help us figure out how to name it. For instance, if the issue is that we can't rely on Objective-C reference counts, we might reverse the sense of the call and name it `mayBeShared(_:)` or `mayHaveOtherReferences(_:)`.
> 
> -- 
> Brent Royal-Gordon
> Architechies
> 



More information about the swift-evolution mailing list