jmmortega / NSUtils

A bunch of extension methods, classes and libraries to get common code
1 stars 4 forks source link

iOS Storage getters cant discern previously defined keys #11

Open DiegoFaFe opened 7 years ago

DiegoFaFe commented 7 years ago

Lets take as an example GetBoolTrue, it wont ever work, cause if its not previosly defined iOS will return a default value that u're not able to set, in bool's case false public bool GetBoolTrue(string key) { try { return _prefs.BoolForKey(key); } catch { return true; } }

There are 3 ways to solve this and keep coherence between platforms:

  1. Delete GetBoolTrue and set default value in android to match ios' ones
  2. Change internal storage in iOS to strings, so value in a non-defined key will be null, that way we can control it and return ur desired default value checking for it
  3. Change the getters to use (NSObject)[https://developer.xamarin.com/api/property/Foundation.NSUserDefaults.Item/p/System.String/], if the key is not defined it'll return a null object and we can check for it
jmmortega commented 7 years ago

:+1