Thanks a lot Hooman, I understand better now.
The part that tripped me was the fact that value types would be copied every
time.
I didn’t realise I wasn’t making a copy of the value type in my program, the
same instance of the value type was getting passed (as Quinn and you had
pointed out).
> On Jul 24, 2017, at 2:38 AM, somu subscribe via swift-users
> wrote:
>
> Thank a lot Quinn, your solution to use inout works well without crashing.
>
> Question 1:
> - Also changing Helper to a class doesn’t seem to crash. Is that a solution
> that wouldn’t cause a
Thanks a lot Zhao, using a serial queue works.
So both the solutions works, thanks.
> On 24 Jul 2017, at 5:39 PM, Zhao Xin via swift-users
> wrote:
>
> You can use serial queue.
>
> class Car {
> var helper = Helper()
> lazy private var queue =
Thanks Joanna Carter, sorry forgot to mention it uses generics, so would
contain associatedtype if protocol is used.
Is the below mentioned approach the usual way to hide implementation details or
is there a better approach ?
With this approach, I had to pass functions of C1 as closures into
> Background:
> Just a little background into what I was trying to achieve (I could be wrong):
>
> - I have a set of classes C1, C2, C3 which has a lot of common code
>
> - I would like to build something that can be reused without exposing the
> implementation details. (I can subclass but
You can use serial queue.
class Car {
var helper = Helper()
lazy private var queue = DispatchQueue(label: "my queue")
func test() {
helper.doSomething(f1: f1)
}
func f1() {
queue.async {
_ = self.helper.v1 //Crash - Simultaneous accesses
Thank a lot Quinn, your solution to use inout works well without crashing.
Question 1:
- Also changing Helper to a class doesn’t seem to crash. Is that a solution
that wouldn’t cause a crash or just works by chance ?
Background:
Just a little background into what I was trying to achieve (I
On 24 Jul 2017, at 07:04, somu subscribe via swift-users
wrote:
> - Is there a bug in my code which is being detected in Xcode 9 ?
Yes. The problem here is that `doSomething(f1:)` is a mutating function, so it
acts like it takes an `inout` reference to `self.helper`.
Hi,
I am having trouble with the below mentioned code.
It crashes in Xcode 9.0 beta 3 (9M174d) but doesn’t crash in Xcode 8.3.3
(8E3004b)
Observations in Xcode 9:
- When Car is changed into a struct and test is made to be mutating, it doesn’t
crash
- When Helper is changed to class, it