Skip to content
This repository has been archived by the owner on Aug 24, 2020. It is now read-only.

Defaults persistence storage abstraction #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Bohr/BOSetting.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
/// The NSUserDefaults value assigned for the key defined on the cell.
@property (nonatomic, assign) id value;

/// Can be called as many times as desired but the new value will only be applied if the current value is nil
- (void)setDefaultValue:(id)value;

/// Instantiates a new BOSetting object with a key.
+ (instancetype)settingWithKey:(NSString *)key;

Expand Down
6 changes: 6 additions & 0 deletions Bohr/BOSetting.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ - (void)setValue:(id)value {
}
}

- (void)setDefaultValue:(id)value {
if (!self.value) {
self.value = value;
}
}

- (void)setValueDidChangeBlock:(void (^)(void))valueDidChangeBlock {
_valueDidChangeBlock = valueDidChangeBlock;
if (valueDidChangeBlock) valueDidChangeBlock();
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ Here's an example of a really simple setup included in the demo project. Please
}
```

You can also set default values during boostrapping of your app :
```obj-c
[[BOSetting settingWithKey:@"fontfamily"] setDefaultValue:@"verdana"];
[[BOSetting settingWithKey:@"fontsize"] setDefaultValue:@(16)];
```
These values will only be applied if the current value of these settings are nil, so you can call these methods at every launch without prior-checks.


#### Built-in BOTableViewCell's

There's a bunch of built-in `BOTableViewCell` subclasses ready to be used:
Expand Down