Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Observing UserDefaults key for change does not work with .'s in the key #3569

Closed
nnascim opened this issue Feb 12, 2018 · 1 comment
Closed

Comments

@nnascim
Copy link

nnascim commented Feb 12, 2018

Line 187 in NSObject+KeyValueObserving.swift:

let components = keyPath.components(separatedBy: ".")
in

static func observe(
		_ object: NSObject,
		keyPath: String,
		options: NSKeyValueObservingOptions,
		action: @escaping (_ value: AnyObject?) -> Void
	) -> AnyDisposable { }

Separating the keyPath String by components is not compatible with UserDefaults:

let key = "io.chuva.token"
let producer = UserDefaults.standard.reactive.producer(forKeyPath: key)

The key is just a String and as such is valid for UserDefaults, however, the above producer will not emit any values.

I have included a test file. Test testKeyWithDotIsObserved() fails.
DefaultsTests.swift.txt

@RuiAAPeres
Copy link
Member

Hello. 👋 Thanks for opening this issue. Due to inactivity, we will soft close the issue. If you feel that it should remain open, please let us know. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants