1

I am new at rxswift framework.I have written a code below and I am not sure.Is there any retain cycle? Must I use weak reference to self?

    loginButton.rx.tap.bind {
        print(self.nameText.value ??  "")
       self.nameText.accept("ahmet vefa saruhan")
    }.disposed(by: disposebag)

second case is :

func myTestFunction(handler : () -> Void) {
    handler()
}

myTestFunction {
        self.isVisible = false
    }

is here any retain cycle problem?

ahmetvefa53
  • 581
  • 6
  • 20

1 Answers1

3

Yes, weak should be used when you using self inside block. And use subscribe instead of bind.

basicLoginButton.rx.tap.subscribe(onNext: { [weak self] () in
    print(self?.nameText.value ?? "")
    self?.nameText.accept("ahmet vefa saruhan")
}).disposed(by: disposeBag)

I think in the second case, everything is correct, there is not needed 'weak'.

Khoren Markosyan
  • 208
  • 1
  • 2
  • 7