Skip to content

Commit

Permalink
Merge pull request #43 from ikesyo/remove-staticstring-workarounds
Browse files Browse the repository at this point in the history
Remove workarounds for compiler warning about StaticString
  • Loading branch information
neilpa committed Sep 21, 2015
2 parents fe09d64 + f4ee8f7 commit 64eb2ff
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions Source/Foundation/Association.swift
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

0 comments on commit 64eb2ff

Please sign in to comment.