jamesmontemagno / SettingsPlugin

Read and Write Settings Plugin for Xamarin and Windows
MIT License
324 stars 80 forks source link

Clarification on AddOrUpdateValue method return value #93

Closed Aumnia closed 7 years ago

Aumnia commented 7 years ago

Hi,

I have been writing my settings properties like:

public int Total {
    get => AppSettings.GetValueOrDefault(nameof(Total), 10);
    set {
        if (AppSettings.AddOrUpdateValue(nameof(Total), value)) {
            RaisePropertyChanged();
        }
    }
}

Based on the docs and this method comment:

// Returns:
//     True of was added or updated and you need to save it.
bool AddOrUpdateValue(string key, int value, string fileName = null);

But while debugging it seems the property changed event is always fired even when the incoming value is the same as the stored value.

Checked the src and AddOrUpdateValueCore's last statement is return true;?

Have I misunderstood?

Thank you!

jamesmontemagno commented 7 years ago

It does not check to see if the value actually changed to something different, just that it was updated. You want to check the values:

https://github.com/jamesmontemagno/SettingsPlugin/blob/master/docs/DataBindingToSettings.md