mirror of https://github.com/SnapKit/SnapKit
Fix up debug labels accessors
This commit is contained in:
parent
46c02e3cc9
commit
de00f5e87e
|
@ -30,20 +30,20 @@
|
||||||
|
|
||||||
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)
|
||||||
|
}
|
||||||
|
public func label() -> String? {
|
||||||
return objc_getAssociatedObject(self.target, &labelKey) as? 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
|
private var labelKey: UInt8 = 0
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -490,4 +490,8 @@ class SnapKitTests: XCTestCase {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
func testCanSetLabel() {
|
||||||
|
self.container.snp.setLabel("Hello World")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue