문제

How can I bind UISwitch.on with the value for a key in NSUserDefaults?

도움이 되었습니까?

해결책

You can bind them (two-way binding) by following:

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

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

The switch's on state starts with the value from the user defaults or NO.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top