diff --git a/.travis.yml b/.travis.yml index 294eb13..ebd8151 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode8 +osx_image: xcode9 env: - ACTION=test PLATFORM=Mac DESTINATION='platform=OS X' diff --git a/SnapKit.xcodeproj/project.pbxproj b/SnapKit.xcodeproj/project.pbxproj index 91d18f6..9bdb554 100644 --- a/SnapKit.xcodeproj/project.pbxproj +++ b/SnapKit.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 2DBA080E1F1FAD66001CFED4 /* Typealiases.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DBA080D1F1FAD66001CFED4 /* Typealiases.swift */; }; EE235F5F1C5785BC00C08960 /* Debugging.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F5E1C5785BC00C08960 /* Debugging.swift */; }; EE235F6D1C5785C600C08960 /* Constraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F621C5785C600C08960 /* Constraint.swift */; }; EE235F701C5785C600C08960 /* ConstraintDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F631C5785C600C08960 /* ConstraintDescription.swift */; }; @@ -46,6 +47,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 2DBA080D1F1FAD66001CFED4 /* Typealiases.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Typealiases.swift; sourceTree = ""; }; 537DCE9A1C35CD4100B5B899 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.1.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; EE235F5E1C5785BC00C08960 /* Debugging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Debugging.swift; sourceTree = ""; }; EE235F621C5785C600C08960 /* Constraint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constraint.swift; sourceTree = ""; }; @@ -178,6 +180,7 @@ isa = PBXGroup; children = ( EE235F621C5785C600C08960 /* Constraint.swift */, + 2DBA080D1F1FAD66001CFED4 /* Typealiases.swift */, EE235F631C5785C600C08960 /* ConstraintDescription.swift */, EE235F641C5785C600C08960 /* ConstraintInsets.swift */, EE235F651C5785C600C08960 /* ConstraintConfig.swift */, @@ -373,6 +376,7 @@ EEF68FA61D784A5300980C26 /* ConstraintDSL.swift in Sources */, EE235FBB1C5785D400C08960 /* ConstraintMakerExtendable.swift in Sources */, EE235F881C5785C600C08960 /* ConstraintItem.swift in Sources */, + 2DBA080E1F1FAD66001CFED4 /* Typealiases.swift in Sources */, EE235F9A1C5785CE00C08960 /* ConstraintPriorityTarget.swift in Sources */, EEF68FC01D7865AA00980C26 /* ConstraintLayoutSupport.swift in Sources */, EEF68FB01D784FB100980C26 /* ConstraintLayoutGuide+Extensions.swift in Sources */, diff --git a/Source/Constraint.swift b/Source/Constraint.swift index cd53ade..2720745 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -89,7 +89,7 @@ public final class Constraint { for layoutFromAttribute in layoutFromAttributes { // get layout to attribute - let layoutToAttribute: NSLayoutAttribute + let layoutToAttribute: LayoutAttribute #if os(iOS) || os(tvOS) if layoutToAttributes.count > 0 { if self.from.attributes == .edges && self.to.attributes == .margins { @@ -166,7 +166,7 @@ public final class Constraint { layoutConstraint.label = self.label // set priority - layoutConstraint.priority = UILayoutPriority(rawValue: self.priority.constraintPriorityTargetValue) + layoutConstraint.priority = LayoutPriority(rawValue: self.priority.constraintPriorityTargetValue) // set constraint layoutConstraint.constraint = self @@ -244,7 +244,7 @@ public final class Constraint { let requiredPriority = ConstraintPriority.required.value if (layoutConstraint.priority.rawValue < requiredPriority), (self.priority.constraintPriorityTargetValue != requiredPriority) { - layoutConstraint.priority = UILayoutPriority(rawValue: self.priority.constraintPriorityTargetValue) + layoutConstraint.priority = LayoutPriority(rawValue: self.priority.constraintPriorityTargetValue) } } } diff --git a/Source/ConstraintAttributes.swift b/Source/ConstraintAttributes.swift index 4083235..10bddb1 100644 --- a/Source/ConstraintAttributes.swift +++ b/Source/ConstraintAttributes.swift @@ -103,8 +103,8 @@ internal struct ConstraintAttributes : OptionSet { @available(iOS 8.0, *) internal static var centerWithinMargins: ConstraintAttributes { return self.init(786432) } - internal var layoutAttributes:[NSLayoutAttribute] { - var attrs = [NSLayoutAttribute]() + internal var layoutAttributes:[LayoutAttribute] { + var attrs = [LayoutAttribute]() if (self.contains(ConstraintAttributes.left)) { attrs.append(.left) } diff --git a/Source/ConstraintConstantTarget.swift b/Source/ConstraintConstantTarget.swift index 801bb79..bc6d596 100644 --- a/Source/ConstraintConstantTarget.swift +++ b/Source/ConstraintConstantTarget.swift @@ -42,7 +42,7 @@ extension ConstraintInsets: ConstraintConstantTarget { extension ConstraintConstantTarget { - internal func constraintConstantTargetValueFor(layoutAttribute: NSLayoutAttribute) -> CGFloat { + internal func constraintConstantTargetValueFor(layoutAttribute: LayoutAttribute) -> CGFloat { if let value = self as? CGFloat { return value } diff --git a/Source/ConstraintInsets.swift b/Source/ConstraintInsets.swift index 6ecac6b..738ca05 100644 --- a/Source/ConstraintInsets.swift +++ b/Source/ConstraintInsets.swift @@ -31,5 +31,5 @@ #if os(iOS) || os(tvOS) public typealias ConstraintInsets = UIEdgeInsets #else - public typealias ConstraintInsets = EdgeInsets + public typealias ConstraintInsets = NSEdgeInsets #endif diff --git a/Source/ConstraintRelation.swift b/Source/ConstraintRelation.swift index d53bb3b..446aaf7 100644 --- a/Source/ConstraintRelation.swift +++ b/Source/ConstraintRelation.swift @@ -33,7 +33,7 @@ internal enum ConstraintRelation : Int { case lessThanOrEqual case greaterThanOrEqual - internal var layoutRelation: NSLayoutRelation { + internal var layoutRelation: LayoutRelation { get { switch(self) { case .equal: diff --git a/Source/ConstraintViewDSL.swift b/Source/ConstraintViewDSL.swift index 4485da4..298bdb1 100644 --- a/Source/ConstraintViewDSL.swift +++ b/Source/ConstraintViewDSL.swift @@ -56,7 +56,7 @@ public struct ConstraintViewDSL: ConstraintAttributesDSL { return self.view.contentHuggingPriority(for: .horizontal).rawValue } set { - self.view.setContentHuggingPriority(UILayoutPriority(rawValue: newValue), for: .horizontal) + self.view.setContentHuggingPriority(LayoutPriority(rawValue: newValue), for: .horizontal) } } @@ -65,7 +65,7 @@ public struct ConstraintViewDSL: ConstraintAttributesDSL { return self.view.contentHuggingPriority(for: .vertical).rawValue } set { - self.view.setContentHuggingPriority(UILayoutPriority(rawValue: newValue), for: .vertical) + self.view.setContentHuggingPriority(LayoutPriority(rawValue: newValue), for: .vertical) } } @@ -74,7 +74,7 @@ public struct ConstraintViewDSL: ConstraintAttributesDSL { return self.view.contentCompressionResistancePriority(for: .horizontal).rawValue } set { - self.view.setContentCompressionResistancePriority(UILayoutPriority(rawValue: newValue), for: .horizontal) + self.view.setContentCompressionResistancePriority(LayoutPriority(rawValue: newValue), for: .horizontal) } } @@ -83,7 +83,7 @@ public struct ConstraintViewDSL: ConstraintAttributesDSL { return self.view.contentCompressionResistancePriority(for: .vertical).rawValue } set { - self.view.setContentCompressionResistancePriority(UILayoutPriority(rawValue: newValue), for: .vertical) + self.view.setContentCompressionResistancePriority(LayoutPriority(rawValue: newValue), for: .vertical) } } diff --git a/Source/Debugging.swift b/Source/Debugging.swift index d57dde5..55f5b87 100644 --- a/Source/Debugging.swift +++ b/Source/Debugging.swift @@ -77,7 +77,7 @@ public extension LayoutConstraint { } -private func descriptionForRelation(_ relation: NSLayoutRelation) -> String { +private func descriptionForRelation(_ relation: LayoutRelation) -> String { switch relation { case .equal: return "==" case .greaterThanOrEqual: return ">=" @@ -85,7 +85,7 @@ private func descriptionForRelation(_ relation: NSLayoutRelation) -> String { } } -private func descriptionForAttribute(_ attribute: NSLayoutAttribute) -> String { +private func descriptionForAttribute(_ attribute: LayoutAttribute) -> String { #if os(iOS) || os(tvOS) switch attribute { case .notAnAttribute: return "notAnAttribute" diff --git a/Source/Typealiases.swift b/Source/Typealiases.swift new file mode 100644 index 0000000..599c522 --- /dev/null +++ b/Source/Typealiases.swift @@ -0,0 +1,22 @@ +// +// Typealiases.swift +// SnapKit +// +// Created by Raimon Lapuente on 19/07/2017. +// Copyright © 2017 SnapKit Team. All rights reserved. +// + +import Foundation + +#if os(iOS) || os(tvOS) + import UIKit + typealias LayoutRelation = NSLayoutRelation + typealias LayoutAttribute = NSLayoutAttribute + typealias LayoutPriority = UILayoutPriority +#else + import AppKit + typealias LayoutRelation = NSLayoutConstraint.Relation + typealias LayoutAttribute = NSLayoutConstraint.Attribute + typealias LayoutPriority = NSLayoutConstraint.Priority +#endif + diff --git a/Tests/Tests.swift b/Tests/Tests.swift index 34f74ac..db414ff 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -395,7 +395,7 @@ class SnapKitTests: XCTestCase { let constraints = view.snp_constraints as! [NSLayoutConstraint] // no guarantee which order the constraints are in, but we should test their couple - let widthHeight = (NSLayoutAttribute.width.rawValue, NSLayoutAttribute.height.rawValue) + let widthHeight = (LayoutAttribute.width.rawValue, LayoutAttribute.height.rawValue) let heightWidth = (widthHeight.1, widthHeight.0) let firstSecond = (constraints[0].firstAttribute.rawValue, constraints[1].firstAttribute.rawValue) @@ -416,10 +416,11 @@ class SnapKitTests: XCTestCase { XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints") - let constraints = self.container.snp_constraints as! [NSLayoutConstraint] + if let constraints = self.container.snp_constraints as? [NSLayoutConstraint], constraints.count > 0 { - XCTAssertEqual(constraints[0].constant, 50, "Should be 50") - XCTAssertEqual(constraints[1].constant, 50, "Should be 50") + XCTAssertEqual(constraints[0].constant, 50, "Should be 50") + XCTAssertEqual(constraints[1].constant, 50, "Should be 50") + } } func testConstraintIdentifier() { @@ -436,8 +437,8 @@ class SnapKitTests: XCTestCase { } func testEdgesToEdges() { - var fromAttributes = Set() - var toAttributes = Set() + var fromAttributes = Set() + var toAttributes = Set() let view = View() self.container.addSubview(view)