While subscribing to a subject, I am calling a method that takes in the value received from the subject. I came across a syntax in the code where that value is not passed in explicitly as an argument, nor the method was forced to use self keyboard before calling it. Q1. Could someone please shed some light on this syntax? Q2. Does this mean that there is a strong reference to self?
.subscribe(onNext: updateNewNumber(from:))
Just to reiterate, the subject is passing simply an integer.
CodePudding user response:
Q1: It's call "point-free style". It's a way of passing a function around as a variable.
If updateNewNumber(from:)
is a method, then it's the same as:
.subscribe(onNext: { self.updateNewNumber(from: $0) }
If it's a free function, then it's the same as:
.subscribe(onNext: { updateNewNumber(from: $0) }
Q2: There is not a strong reference to the method, but there is a strong reference to self
as indicated by the above.