Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread John McCall via swift-users
> On Nov 18, 2016, at 3:10 PM, Karl wrote: > > >> On 18 Nov 2016, at 20:18, John McCall > > wrote: >> >>> >>> On Nov 18, 2016, at 7:40 AM, Karl >> > wrote: >>> >>> On 18 Nov 2016, at 13:05, Adrian Zubarev via swift-users mailt

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread Karl via swift-users
> On 18 Nov 2016, at 20:18, John McCall wrote: > >> >> On Nov 18, 2016, at 7:40 AM, Karl > > wrote: >> >> >>> On 18 Nov 2016, at 13:05, Adrian Zubarev via swift-users >>> mailto:swift-users@swift.org>> wrote: >>> >>> Hi there, >>> >>> I just can’t get my head aro

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread Adrian Zubarev via swift-users
Hi John, Thank you for your huge and informative answer. Only after reading it I’ve realized that I made a couple mistakes in my code snippets. Thank you for correcting me. :) I also have done some further digging and found a thread [swift-dev] [idle] COW wrapper in 30 lines which explains a f

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread John McCall via swift-users
> On Nov 18, 2016, at 7:40 AM, Karl wrote: > > >> On 18 Nov 2016, at 13:05, Adrian Zubarev via swift-users >> mailto:swift-users@swift.org>> wrote: >> >> Hi there, >> >> I just can’t get my head around mutable views and COW. >> >> Here is a small example: >> >> final class Storage { >>

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread Adrian Zubarev via swift-users
What exactly to you mean by unsafe/invalide? If you refer to unowned than yes this is incorrect. That was only part of the first question about isKnownUniquelyReferenced, where I myself missed the part from the docs that says that weak references don’t affect the result. In general DocumentValu

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread Karl via swift-users
> On 18 Nov 2016, at 16:40, Karl wrote: > > >> On 18 Nov 2016, at 13:05, Adrian Zubarev via swift-users >> mailto:swift-users@swift.org>> wrote: >> >> Hi there, >> >> I just can’t get my head around mutable views and COW. >> >> Here is a small example: >> >> final class Storage { >>

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread Karl via swift-users
> On 18 Nov 2016, at 13:05, Adrian Zubarev via swift-users > wrote: > > Hi there, > > I just can’t get my head around mutable views and COW. > > Here is a small example: > > final class Storage { > > var keys: [String] = [] > var values: [Int] = [] > } > > public struct Docume

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread Adrian Zubarev via swift-users
Nah it’s okay mate. ;) This is the right list, because I ask for help. COW stands for copy-on-write. If you’re interesting on learning something new, read this paragraph https://github.com/apple/swift/blob/7e68e02b4eaa1cf44037a383129cbef60ea55d67/docs/OptimizationTips.rst#advice-use-copy-on-writ

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread Zhao Xin via swift-users
Sorry. If you are doing something on implementing proposals, you should use [swift-dev] list instead. Yes. I do don't know what the COW means. Zhaoxin On Fri, Nov 18, 2016 at 11:09 PM, Adrian Zubarev < adrian.zuba...@devandartist.com> wrote: > I’m sorry but you seem not to understand what I’m as

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread Zhao Xin via swift-users
protocol Copyable { func copy() -> Self } final class Storage:Copyable { var keys: [String] = [] var values: [Int] = [] func copy() -> Storage { let s = Storage() s.keys = keys s.values = values return s } } public struct Docu

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread Adrian Zubarev via swift-users
I’m sorry but you seem not to understand what I’m asking for! If you don’t know what a mutable view is, please read this proposal to get the basic idea: https://github.com/natecook1000/swift-evolution/blob/nc-dictionary-collections/proposals/-dictionary-key-and-value-collections.md Your ans

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread Adrian Zubarev via swift-users
Ups sorry for CCing the post to the evolution list. That happens from time to time. :/ --  Adrian Zubarev Sent with Airmail Am 18. November 2016 um 15:07:43, Adrian Zubarev (adrian.zuba...@devandartist.com) schrieb: I apologize about the weak/unowned issue I mentioned. I kinda missed that p

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread Adrian Zubarev via swift-users
This doesn’t make any sense. Somewhere from the Swift book: Weak and unowned references enable one instance in a reference cycle to refer to the other instance without keeping a strong hold on it. The instances can then refer to each other without creating a strong reference cycle. From the sdl

Re: [swift-users] Problem with mutable views and COW

2016-11-18 Thread Zhao Xin via swift-users
>Why is the second check false, even if the property is marked as unowned for the view? Please search the mailing list, this is not the first time it comes as a new question. Shortly speaking, it is `false` only because you used `unowned`. If you you can grantee it always exists. Just use it direc

[swift-users] Problem with mutable views and COW

2016-11-18 Thread Adrian Zubarev via swift-users
Hi there, I just can’t get my head around mutable views and COW. Here is a small example: final class Storage { var keys: [String] = [] var values: [Int] = [] } public struct Document { var _storageReference: Storage public init() { self._stor