davdroman / Bohr

Settings screen composing framework
MIT License
1.26k stars 83 forks source link

Ability to observe the values changes #24

Closed owlcoding closed 8 years ago

owlcoding commented 8 years ago

If I'm storing my settings on some external server, I'd love to have a way to monitor their changes. Right now I'm doing it in the .visibilityBlock, with the key set to the field's key:

    [section addCell:[BOSwitchTableViewCell cellWithTitle:@"Push Notifications" key:@"push_notif" handler:^(BOSwitchTableViewCell *cell) {
        cell.visibilityKey = @"push_notif";
        cell.visibilityBlock = ^BOOL (id settingValue ){
            [self setPushTo:[settingValue boolValue]];
            return YES;
        };

    }]];

but I doubt this is the preferred way to handle it.

With BOButtonTableViewCell I have an access to the .actionBlock, but with other cell types it's not there, even it could be useful.

davdroman commented 8 years ago

Hi @owlcoding. Thanks for taking some time to open this issue :smile:

As mentioned in #13, UI isn't the best choice to trigger any observation-based action. Instead, I recommend you observing NSUserDefaults directly as a better practise. That way, whether Bohr or any other external entity makes a change to a certain key, you'll be able to handle it seamlessly. If you only observed Bohr changes, you'd have the risk of any other component in your app affecting NSUserDefaults and not responding accordingly.

I always like third opinions in feature matters, so thoughts on this are totally welcome.