[swift-users] @NSCopying semantic does not appear to copy in Swift initializer

Torin Kwok torin at kwok.im
Mon Jan 30 04:12:37 CST 2017


In Obj-C, if a property has promised that it conforms to <NSCopying>
porotocl and that it would respect copying semantic by being qualified
with `@property (copy)`, then we assign a value to `ivar` through the
setter by writting down `self.ivar = whatever` in `-init`, accessing
would not be direct but via the setter. This behaviour, in fact, doesn't
match Obj-C conventions.

Quinn The Eskimo! via swift-users writes:

> On 27 Jan 2017, at 18:56, Jordan Rose via swift-users <swift-users at swift.org> wrote:
>
>> @NSCopying currently does not affect initializers.  … it's not 100%, for-sure a bug.
>
> Just by way of context, this current behaviour closely matches Objective-C conventions, where `-init` methods directly access ivars and are expected to do any necessary copies.
>
> Share and Enjoy


-- 
Torin Kwok (郭桐)
OpenPGP/GnuPG: https://keybase.io/kwok


More information about the swift-users mailing list