@@ -236,8 +236,8 @@ - (void)viewWillAppear:(BOOL)animated {
236236 }
237237
238238 NSNotificationCenter *dc = NSNotificationCenter .defaultCenter ;
239- [dc removeObserver: self name: kIASKAppSettingChanged object: nil ];
240- [dc addObserver: self selector: @selector (didChangeSettingViaIASK: ) name: kIASKAppSettingChanged object: nil ];
239+ [dc removeObserver: self name: kIASKInternalAppSettingChanged object: nil ];
240+ [dc addObserver: self selector: @selector (didChangeSettingViaIASK: ) name: kIASKInternalAppSettingChanged object: nil ];
241241 if ([self .settingsStore isKindOfClass: [IASKSettingsStoreUserDefaults class ]]) {
242242 IASKSettingsStoreUserDefaults *udSettingsStore = (id )self.settingsStore ;
243243 [dc removeObserver: self name: NSUserDefaultsDidChangeNotification object: udSettingsStore.defaults];
@@ -272,7 +272,7 @@ - (void)viewDidDisappear:(BOOL)animated NS_EXTENSION_UNAVAILABLE("Uses APIs (i.e
272272 if ([self .settingsStore isKindOfClass: [IASKSettingsStoreUserDefaults class ]]) {
273273 IASKSettingsStoreUserDefaults *udSettingsStore = (id )self.settingsStore ;
274274 [dc removeObserver: self name: NSUserDefaultsDidChangeNotification object: udSettingsStore.defaults];
275- [dc removeObserver: self name: kIASKAppSettingChanged object: self ];
275+ [dc removeObserver: self name: kIASKInternalAppSettingChanged object: nil ];
276276 }
277277 [dc removeObserver: self name: UIApplicationDidEnterBackgroundNotification object: UIApplication.sharedApplication];
278278 [dc removeObserver: self name: UIApplicationWillEnterForegroundNotification object: UIApplication.sharedApplication];
@@ -452,18 +452,14 @@ - (void)setSpecifier:(IASKSpecifier*)specifier on:(BOOL)on {
452452 NSIndexPath * indexPath = [_settingsReader indexPathForKey: key];
453453 UITableViewCell* cell = [self .tableView cellForRowAtIndexPath: indexPath];
454454 cell.detailTextLabel .text = [specifier subtitleForValue: on ? @" YES" : @" NO" ];
455+ [self postChange: specifier value: [self .settingsStore objectForSpecifier: specifier]];
455456 }
456- [[NSNotificationCenter defaultCenter ] postNotificationName: kIASKAppSettingChanged
457- object: self
458- userInfo: @{(id )specifier.key : [self .settingsStore objectForSpecifier: specifier] ?: NSNull .null }];
459457}
460458
461459- (void )sliderChangedValue : (id )sender {
462460 IASKSlider *slider = (IASKSlider*)sender;
463461 [self .settingsStore setFloat: slider.value forSpecifier: slider.specifier];
464- [[NSNotificationCenter defaultCenter ] postNotificationName: kIASKAppSettingChanged
465- object: self
466- userInfo: @{(id )slider.specifier .key : @(slider.value )}];
462+ [self postChange: slider.specifier value: @(slider.value)];
467463}
468464
469465- (void )datePickerChangedValue : (IASKDatePicker*)datePicker {
@@ -472,6 +468,7 @@ - (void)datePickerChangedValue:(IASKDatePicker*)datePicker {
472468 [self .delegate settingsViewController: self setDate: datePicker.date forSpecifier: datePicker.specifier];
473469 } else {
474470 [self .settingsStore setObject: datePicker.date forSpecifier: datePicker.specifier];
471+ [self postChange: datePicker.specifier value: datePicker.date];
475472 }
476473 datePicker.editing = NO ;
477474}
@@ -1077,8 +1074,8 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
10771074 [self .settingsStore removeObjectWithSpecifier: specifier];
10781075 [tableView deleteRowsAtIndexPaths: @[indexPath] withRowAnimation: UITableViewRowAnimationAutomatic];
10791076
1080- NSDictionary *userInfo = specifier. parentSpecifier . key && [self .settingsStore objectForSpecifier: ( id ) specifier.parentSpecifier] ? @{( id )specifier. parentSpecifier . key : [ self .settingsStore objectForSpecifier: ( id )specifier.parentSpecifier] ?: @[]} : nil ;
1081- [ NSNotificationCenter .defaultCenter postNotificationName: kIASKAppSettingChanged object: self userInfo: userInfo ];
1077+ [self postChange: specifier.parentSpecifier
1078+ value: [ self .settingsStore objectForSpecifier: specifier.parentSpecifier] ?: @[] ];
10821079}
10831080
10841081- (void )presentChildViewController : (UITableViewController<IASKViewController> *)targetViewController specifier : (IASKSpecifier *)specifier indexPath : (NSIndexPath *)indexPath {
@@ -1094,7 +1091,7 @@ - (void)presentChildViewController:(UITableViewController<IASKViewController> *)
10941091 if ([value isKindOfClass: NSDictionary .class]) {
10951092 itemDict = value;
10961093 } else if (specifier.key && value) {
1097- itemDict = @{( id ) specifier.key : value};
1094+ itemDict = @{specifier.key : value};
10981095 }
10991096 }
11001097 IASKSettingsStoreInMemory *inMemoryStore = [[IASKSettingsStoreInMemory alloc ] initWithDictionary: itemDict];
@@ -1130,8 +1127,9 @@ - (void)presentChildViewController:(UITableViewController<IASKViewController> *)
11301127 } else {
11311128 [weakSelf.settingsStore setObject: inMemoryStore.dictionary forSpecifier: specifier];
11321129 }
1133- NSDictionary *userInfo = specifier.parentSpecifier .key && [weakSelf.settingsStore objectForSpecifier: (id )specifier.parentSpecifier] ? @{(id )specifier.parentSpecifier .key : (id )[weakSelf.settingsStore objectForSpecifier: (id )specifier.parentSpecifier]} : nil ;
1134- [NSNotificationCenter .defaultCenter postNotificationName: kIASKAppSettingChanged object: weakSelf userInfo: userInfo];
1130+ [weakSelf postChange: specifier.parentSpecifier
1131+ value: [weakSelf.settingsStore objectForSpecifier: specifier.parentSpecifier]];
1132+
11351133 [weakSelf.tableView reloadData ];
11361134 };
11371135 self.childPaneHandler (NO ); // perform initial validation
@@ -1208,10 +1206,7 @@ - (BOOL)textField:(IASKTextField*)textField shouldChangeCharactersInRange:(NSRan
12081206 }
12091207 if (storeToSettings) {
12101208 [self .settingsStore setObject: newText forSpecifier: textField.specifier];
1211- NSDictionary *userInfo = textField.specifier .key && newText ? @{(id )textField.specifier .key : newText} : nil ;
1212- [NSNotificationCenter .defaultCenter postNotificationName: kIASKAppSettingChanged
1213- object: self
1214- userInfo: userInfo];
1209+ [self postChange: textField.specifier value: newText];
12151210 }
12161211 }
12171212 return result != IASKValidationResultOkWithReplacement;
@@ -1251,19 +1246,19 @@ - (void)textFieldDidEndEditing:(IASKTextField *)textField {
12511246 if (![self .settingsStore objectForSpecifier: specifier] && textField.text .length == 0 ) {
12521247 return ;
12531248 }
1249+ NSString * oldValue = [self .settingsStore objectForSpecifier: specifier];
12541250 [self .settingsStore setObject: textField.text forSpecifier: specifier];
12551251 if (specifier.isAddSpecifier ) {
1256- NSUInteger section = [self .settingsReader indexPathForKey: ( id ) specifier.parentSpecifier.key].section ;
1252+ NSUInteger section = [self .settingsReader indexPathForKey: specifier.parentSpecifier.key].section ;
12571253 NSUInteger row = [self tableView: self .tableView numberOfRowsInSection: section] - 2 ;
12581254 NSIndexPath *indexPath = [NSIndexPath indexPathForRow: row inSection: section];
12591255 [self .tableView insertRowsAtIndexPaths: @[indexPath] withRowAnimation: UITableViewRowAnimationAutomatic];
12601256 indexPath = [NSIndexPath indexPathForRow: row + 1 inSection: section];
12611257 [self .tableView reloadRowsAtIndexPaths: @[indexPath] withRowAnimation: UITableViewRowAnimationAutomatic];
12621258 }
1263- NSDictionary *userInfo = specifier.key && textField.text ? @{(id )specifier.key : (id )textField.text } : nil ;
1264- [NSNotificationCenter .defaultCenter postNotificationName: kIASKAppSettingChanged
1265- object: self
1266- userInfo: userInfo];
1259+ if (textField.text && ![oldValue isEqual: textField.text]) {
1260+ [self postChange: specifier value: textField.text];
1261+ }
12671262 break ;
12681263 }
12691264 case IASKValidationResultFailed:
@@ -1291,17 +1286,15 @@ - (void)textViewDidChange:(IASKTextView *)textView {
12911286 [self cacheRowHeightForTextView: textView animated: YES ];
12921287
12931288 CGRect visibleTableRect = UIEdgeInsetsInsetRect (self.tableView .bounds , self.tableView .contentInset );
1294- NSIndexPath *indexPath = [self .settingsReader indexPathForKey: ( id ) textView.specifier.key];
1289+ NSIndexPath *indexPath = [self .settingsReader indexPathForKey: textView.specifier.key];
12951290 CGRect cellFrame = [self .tableView rectForRowAtIndexPath: indexPath];
12961291
12971292 if (!CGRectContainsRect (visibleTableRect, cellFrame)) {
12981293 [self .tableView scrollRectToVisible: CGRectInset (cellFrame, 0 , - 30 ) animated: YES ];
12991294 }
13001295
13011296 [self .settingsStore setObject: textView.text forSpecifier: textView.specifier];
1302- [[NSNotificationCenter defaultCenter ] postNotificationName: kIASKAppSettingChanged
1303- object: self
1304- userInfo: @{(id )textView.specifier .key : textView.text }];
1297+ [self postChange: textView.specifier value: textView.text];
13051298
13061299}
13071300
@@ -1372,6 +1365,19 @@ - (void)userDefaultsDidChange {
13721365 });
13731366}
13741367
1368+ - (void )postChange : (IASKSpecifier*)specifier value : (id )value {
1369+ if (!specifier.key ) {
1370+ return ;
1371+ }
1372+ NSDictionary *userInfo = @{specifier.key : value ?: NSNull .null };
1373+ [[NSNotificationCenter defaultCenter ] postNotificationName: kIASKInternalAppSettingChanged
1374+ object: self
1375+ userInfo: userInfo];
1376+ [[NSNotificationCenter defaultCenter ] postNotificationName: IASKSettingChangedNotification
1377+ object: self
1378+ userInfo: userInfo];
1379+ }
1380+
13751381- (void )didChangeSettingViaIASK : (NSNotification *)notification {
13761382 NSString *key = notification.userInfo .allKeys .firstObject ;
13771383 if (key) {
0 commit comments