<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Thank a lot Quinn, your solution to use inout works well without crashing.</div><div class=""><br class=""></div><div class=""><b class="">Question 1:</b></div><div class="">- Also changing&nbsp;<font color="#0433ff" face="Menlo" style="font-size: 11px;" class="">Helper</font>&nbsp;to a&nbsp;<font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">class</span></font>&nbsp;doesn’t seem to crash. Is that a solution that wouldn’t cause a crash or just works by chance ?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><b class="">Background:</b></div><div class="">Just a little background into what I was trying to achieve (<u class="">I could be wrong</u>):</div><div class=""><br class=""></div><div class="">- I have a set of classes&nbsp;<font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">C1</span></font>,&nbsp;<font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">C2</span></font>,&nbsp;<font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">C3</span></font>&nbsp;which has a lot of common code</div><div class=""><br class=""></div><div class="">- I would like to build something that can be reused without exposing the implementation details. (I can subclass but would expose the underlying functions, same applies to&nbsp;<font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">protocol</span></font>&nbsp;as well)</div><div class=""><br class=""></div><div class="">- I thought I would build helper&nbsp;<font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">class</span></font>&nbsp;/&nbsp;<font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">struct</span></font>&nbsp;which would contain the common code. I can make the helper a&nbsp;<font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">private property</span></font>&nbsp;so that the functions wouldn’t be exposed to the instances of&nbsp;<font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">C1</span></font>,&nbsp;<font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">C2</span></font>,&nbsp;<font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">C3</span></font>. In order to achieve that I had to pass some functions from&nbsp;<font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">C1</span></font>&nbsp;into the&nbsp;<font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">Helper</span></font>&nbsp;<font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">struct</span></font>.</div><div class=""><br class=""></div><div class=""><b class="">Question 2:</b></div><div class="">- Is this problem (hiding implementation details) normally tackled using&nbsp;<font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">Helper class</span></font>&nbsp;(or&nbsp;<font color="#0433ff" face="Menlo" class=""><span style="font-size: 11px;" class="">struct</span></font>) or is there a more better approach ?</div><div class=""><br class=""></div><div class="">Thanks and regards,</div><div class="">Muthu</div><div class=""><br class=""></div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On 24 Jul 2017, at 4:14 PM, Quinn The Eskimo! via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class="">On 24 Jul 2017, at 07:04, somu subscribe via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:<br class=""><br class=""><blockquote type="cite" class="">- Is there a bug in my code which is being detected in Xcode 9 ?<br class=""></blockquote><br class="">Yes. &nbsp;The problem here is that `doSomething(f1:)` is a mutating function, so it acts like it takes an `inout` reference to `self.helper`. &nbsp;That’s one mutable reference. &nbsp;It then calls `Car.f1()`, which tries to get a non-mutating reference to exactly the same struct. &nbsp;This is outlawed in Swift 4 as part of the memory ownership effort.<br class=""><br class="">You can read more about the specific change in SE-0176 “Enforce Exclusive Access to Memory”.<br class=""><br class="">&lt;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0176-enforce-exclusive-access-to-memory.md" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0176-enforce-exclusive-access-to-memory.md</a>&gt;<br class=""><br class="">And the general background to this in the “Ownership Manifesto"<br class=""><br class="">&lt;<a href="https://github.com/apple/swift/blob/master/docs/OwnershipManifesto.md" class="">https://github.com/apple/swift/blob/master/docs/OwnershipManifesto.md</a>&gt;<br class=""><br class=""><blockquote type="cite" class="">If so could you please explain and suggest an alternate approach / fix ?<br class=""></blockquote><br class="">It’s hard to offer concrete suggestions without knowing more about your high-level goals. &nbsp;One option is for `doSomething(f1:)` to pass the `inout` reference through to `f1`. &nbsp;For example:<br class=""><br class=""> &nbsp;&nbsp;&nbsp;mutating func doSomething(f1: (inout Helper) -&gt; ()) {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f1(&amp;self)<br class=""> &nbsp;&nbsp;&nbsp;}<br class=""><br class=""> &nbsp;&nbsp;&nbsp;func f1(h: inout Helper) {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_ = h.v1 &nbsp;// no crash<br class=""> &nbsp;&nbsp;&nbsp;}<br class=""><br class="">but whether that makes sense in your code is for you to decide.<br class=""><br class="">Share and Enjoy<br class="">--<br class="">Quinn "The Eskimo!" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;<a href="http://www.apple.com/developer/" class="">http://www.apple.com/developer/</a>&gt;<br class="">Apple Developer Relations, Developer Technical Support, Core OS/Hardware<br class=""><br class=""><br class="">_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></div></blockquote></div><br class=""></body></html>