swift - Binding textfield text to enable button not working -




i new reactive programming, , bond framework specifically. know may doing things wrong in basic understanding of programming technique. situation:

i have uitextview , "approve" uibutton. want approve button enabled when text in textview not nil. have tried adding these lines of code viewdidload method in viewcontroller.

    textview.reactive.text.observenext{(text) in         self.message = text         print(text)     }     textview.reactive.text.map { $0 != nil}.bind(to: approvebuttonoutlet.reactive.isenabled) 

the first action works (printing text happening on every input change). second 1 not work, button enabled both when text not nil , when is.

any appreciated.

you can try like

 rac(self.approvebuttonoutlet, enabled) = [self.textview.rac_textsignal map:^id(nsstring *text) {       return @(text.length > 0);     }]; 

i'm not sure how in swift 3 try like

rac(self.approvebuttonoutlet, enabled) = self.textview.rac_textsignal.map({(text: string) -> void in     return (text.length > 0) }) 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -