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

Remove workarounds for compiler warning about StaticString #43

Merged
merged 1 commit into from
Sep 21, 2015
Merged
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
12 changes: 4 additions & 8 deletions Source/Foundation/Association.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ import ReactiveCocoa
/// This can be used as an alternative to `DynamicProperty` for creating strongly typed
/// bindings on Cocoa objects.
public func associatedProperty(host: AnyObject, keyPath: StaticString) -> MutableProperty<String> {
// Workaround compiler warning when using keyPath.stringValue
let key = "\(keyPath)"
let initial: () -> String = { [weak host] _ in
host?.valueForKeyPath(key) as? String ?? ""
host?.valueForKeyPath(keyPath.stringValue) as? String ?? ""
}
let setter: String -> () = { [weak host] newValue in
host?.setValue(newValue, forKeyPath: key)
host?.setValue(newValue, forKeyPath: keyPath.stringValue)
}
return associatedProperty(host, key: keyPath.utf8Start, initial: initial, setter: setter)
}
Expand All @@ -39,13 +37,11 @@ public func associatedProperty(host: AnyObject, keyPath: StaticString) -> Mutabl
/// N.B. Ensure that `host` isn't strongly captured by `placeholder`, otherwise this will
/// create a retain cycle with `host` causing it to never dealloc.
public func associatedProperty<T: AnyObject>(host: AnyObject, keyPath: StaticString, placeholder: () -> T) -> MutableProperty<T> {
// Workaround compiler warning when using keyPath.stringValue
let key = "\(keyPath)"
let initial: () -> T = { [weak host] _ in
host?.valueForKeyPath(key) as? T ?? placeholder()
host?.valueForKeyPath(keyPath.stringValue) as? T ?? placeholder()
}
let setter: T -> () = { [weak host] newValue in
host?.setValue(newValue, forKeyPath: key)
host?.setValue(newValue, forKeyPath: keyPath.stringValue)
}
return associatedProperty(host, key: keyPath.utf8Start, initial: initial, setter: setter)
}
Expand Down