Fix up debug labels accessors

This commit is contained in:
Robert Payne 2016-09-20 17:08:30 +12:00
parent 46c02e3cc9
commit de00f5e87e
3 changed files with 13 additions and 9 deletions

View File

@ -30,19 +30,19 @@
public protocol ConstraintDSL { public protocol ConstraintDSL {
var label: String? { get set }
var target: AnyObject? { get } var target: AnyObject? { get }
func setLabel(_ value: String?)
func label() -> String?
} }
extension ConstraintDSL { extension ConstraintDSL {
public var label: String? { public func setLabel(_ value: String?) {
get { objc_setAssociatedObject(self.target, &labelKey, value, .OBJC_ASSOCIATION_COPY_NONATOMIC)
return objc_getAssociatedObject(self.target, &labelKey) as? String }
} public func label() -> String? {
set { return objc_getAssociatedObject(self.target, &labelKey) as? String
objc_setAssociatedObject(self.target, &labelKey, newValue, .OBJC_ASSOCIATION_COPY_NONATOMIC)
}
} }
} }

View File

@ -144,7 +144,7 @@ private func descriptionForObject(_ object: AnyObject) -> String {
desc += type(of: object).description() desc += type(of: object).description()
if let object = object as? ConstraintView { if let object = object as? ConstraintView {
desc += ":\(object.snp.label ?? pointerDescription)" desc += ":\(object.snp.label() ?? pointerDescription)"
} else if let object = object as? LayoutConstraint { } else if let object = object as? LayoutConstraint {
desc += ":\(object.label ?? pointerDescription)" desc += ":\(object.label ?? pointerDescription)"
} else { } else {

View File

@ -490,4 +490,8 @@ class SnapKitTests: XCTestCase {
} }
#endif #endif
func testCanSetLabel() {
self.container.snp.setLabel("Hello World")
}
} }