Associate UISwitch State with NSUserDefaults Using ReactiveCocoa

How to associate UISwitch.onwith value for key in NSUserDefaults?

+4
source share
1 answer

You can link them (two-way binding) as follows:

RACChannelTerminal *switchTerminal = self.someSwitch.rac_newOnChannel;
RACChannelTerminal *defaultsTerminal = [[NSUserDefaults standardUserDefaults] rac_channelTerminalForKey:@"someBoolKey"];

[switchTerminal subscribe:defaultsTerminal];
[defaultsTerminal subscribe:switchTerminal];

The state of the switch onstarts with a value from the user defaults or NO.

+8
source

Source: https://habr.com/ru/post/1536759/


All Articles