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,20 +30,20 @@
public protocol ConstraintDSL {
var label: String? { get set }
var target: AnyObject? { get }
func setLabel(_ value: String?)
func label() -> String?
}
extension ConstraintDSL {
public var label: String? {
get {
public func setLabel(_ value: String?) {
objc_setAssociatedObject(self.target, &labelKey, value, .OBJC_ASSOCIATION_COPY_NONATOMIC)
}
public func label() -> String? {
return objc_getAssociatedObject(self.target, &labelKey) as? String
}
set {
objc_setAssociatedObject(self.target, &labelKey, newValue, .OBJC_ASSOCIATION_COPY_NONATOMIC)
}
}
}
private var labelKey: UInt8 = 0

View File

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

View File

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