使用ReactiveCocoa将UISwitch的状态绑定到NSUserDefaults

时间:2014-04-16 10:42:31

标签: objective-c nsuserdefaults uiswitch reactive-cocoa

如何将UISwitch.onNSUserDefaults中的密钥值绑定?

1 个答案:

答案 0 :(得分:9)

您可以通过以下方式绑定它们(双向绑定):

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

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

交换机的on状态以用户默认值或NO的值开头。

相关问题