[swift-evolution] [swift-evolution-announce] [Review] SE-0125: Remove NonObjectiveCBase and isUniquelyReferenced
dabrahams at apple.com
Wed Jul 20 14:44:51 CDT 2016
on Wed Jul 20 2016, Andrew Trick <atrick-AT-apple.com> wrote:
>> On Jul 20, 2016, at 6:12 AM, Arnold Schwaighofer via swift-evolution <swift-evolution at swift.org> wrote:
>>> 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.
>>> var y = SwiftKlazz()
>>> var z = [Any]
>>> The simplification of this proposal just to remove the variant that had the NonObjectiveCBase prerequisite.
>> Your critique of the negation still holds though.
>> So maybe we still rename it from isUniquelyReferencedNonObjC to isUniquelyReferencedSwiftReference?
> What’s the difference between a “SwiftReference” and AnyObject?
> The current name is the literal meaning. The intent of being literal
> and awkward is to encourage users to read the comments. This isn’t
> something people should be embedding in their program logic
> anyway. It’s very special purpose.
> That said, something like “isUniquelyReferencedNativeSwift” would work
> assuming that’s semantically correct (“native" Swfit objects do not
> inherit from NSObject).
It's semantically correct today but I'm not sure it always be. If we
decided interop with Python, for example, we'd be able to detect
uniqueness of Python objects and this method should do so.
> “isKnownUniquelyReferenced” would be fine with a warning in the doc
> comment that it may always return false for objc objects.
That's a better name.
P.S. It's conceivable that someday we could correctly detect uniqueness
in (a subset of) ObjC types.
More information about the swift-evolution