Fast semantics calling method with (null) weak reference using. operator

Back in objective-C with ARC, it was unsafe:

MyClass* someObject = ...
__weak MyClass* weakSomeObject = someObject;
doSomething(^{
    [weakSomeObject someMethod];
});

Why? because simply calling the method does not cause the ARC to save the object, and thus the instance someObjectcan be freed and freed in the middle of executionsomeMethod

Bringing this forward to fast, it is converted as follows:

let someObject: MyClass = ...
doSomething { [weak someObject]
    someObject?.someMethod()
}

My question is: what is the semantics of the operator ?.in the fast sense of ARC and is it safe to use it with weak calls to the reference method?

I can imagine a fast compiler translating the above code into something like this:

let someObject: MyClass = ...
doSomething { [weak someObject]
    if let tmp = someObject { 
        tmp.someMethod()
    }
}

, , tmp , , , ARC someMethod

, , - ARC - .

- , , , ?

+6
2

- , . :

, Swift, :

class MyClass {
  func doSomething() {
      // I can access self in here
  }
}

print(type(of: MyClass.doSomething)) //(MyClass) -> () -> ()

, , , , , self, (()->())

MyClass ( ), self, , .

, MyClass.doSomething (MyClass) -> () -> (), MyClass().doSomething - () -> (), MyClass () -> ().

:

weak var test: MyClass? = MyClass()
test?.doSomething()

2 . -, test nil, MyClass Mylicass type curried (MyClass) -> () ->(). - "", .

()->(), / self .

, , , .

, Swift , .

https://oleb.net/blog/2014/07/swift-instance-methods-curried-functions/


UPDATE:

:

http://rosslebeau.com/2016/sneaky-reference-cycles-swift-instance-methods

https://www.klundberg.com/blog/capturing-objects-weakly-in-instance-method-references-in-swift/

0

:

  • .

  • let, guard .. , , .

?. , , , , , ( ).

weak unowned :

  • weak , , ,

  • unowned, weak , , , , , , .

, .

0

All Articles