From de00f5e87e5be64145157241209c289e7a835810 Mon Sep 17 00:00:00 2001 From: Robert Payne Date: Tue, 20 Sep 2016 17:08:30 +1200 Subject: [PATCH] Fix up debug labels accessors --- Source/ConstraintDSL.swift | 16 ++++++++-------- Source/Debugging.swift | 2 +- Tests/Tests.swift | 4 ++++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Source/ConstraintDSL.swift b/Source/ConstraintDSL.swift index f5248f5..cda83a0 100644 --- a/Source/ConstraintDSL.swift +++ b/Source/ConstraintDSL.swift @@ -30,19 +30,19 @@ 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 { - return objc_getAssociatedObject(self.target, &labelKey) as? String - } - set { - objc_setAssociatedObject(self.target, &labelKey, newValue, .OBJC_ASSOCIATION_COPY_NONATOMIC) - } + 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 } } diff --git a/Source/Debugging.swift b/Source/Debugging.swift index be8bb9e..fdc505d 100644 --- a/Source/Debugging.swift +++ b/Source/Debugging.swift @@ -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 { diff --git a/Tests/Tests.swift b/Tests/Tests.swift index 68cf2b9..c00beb4 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -490,4 +490,8 @@ class SnapKitTests: XCTestCase { } #endif + func testCanSetLabel() { + self.container.snp.setLabel("Hello World") + } + }