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

2017-01-30 Thread Torin Kwok via swift-users
Haha yes, you're right. I misunderstanded your idea, sorry. Indeed, in Obj-C, we have the freedom to decide on whether or not assign a value to a property by invoking setter or by accessing ivar directly and Apple's official documentation apparently suggested that we should always access the instan

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

2017-01-30 Thread Quinn "The Eskimo!" via swift-users
On 30 Jan 2017, at 10:12, Torin Kwok wrote: > In Obj-C, if a property has promised that it conforms to > 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

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

2017-01-30 Thread Torin Kwok via swift-users
In Obj-C, if a property has promised that it conforms to 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

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

2017-01-30 Thread Quinn "The Eskimo!" via swift-users
On 27 Jan 2017, at 18:56, Jordan Rose via swift-users 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 ex

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

2017-01-27 Thread Jordan Rose via swift-users
Your observation is correct: @NSCopying currently does not affect initializers. This is because accessing a property in an initializer always does direct access to the storage rather than going through the setter. It might be reasonable to change this behavior, but it probably deserves a bit of

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

2017-01-27 Thread Rod Brown via swift-users
Hi Torin, Just a few notes: I believe the @NSCopying behaviour actually uses the copy(with zone: NSZone?) method rather than the indirect copy() method. I would check that you’ve implemented that correctly. If you have, then it appears to be a bug. I would breakpoint on this method (not copy()

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

2017-01-26 Thread Torin Kwok via swift-users
Hello guys, I wanna ask a question about the behavior of `@NSCopying` semantic in Swift 3. Well, according to Apple's official documentation: > In Swift, the Objective-C copy property attribute translates to > @NSCopying. The type of the property must conform to the NSCopying > protocol. However