Xcode 4 mac compatibility (#446)

* Typealias the types that are different on mac and ios
Update tests because when failing they where being blocked and stoped running

* try xcode 9 version to see tests pass

* Renaming the Typealiases to remove Generic suffix and NS prefix
This commit is contained in:
Raimon Lapuente 2017-09-17 04:15:34 +02:00 committed by Robert Payne
parent d31148f449
commit e44888b0e4
11 changed files with 48 additions and 21 deletions

View File

@ -1,5 +1,5 @@
language: objective-c language: objective-c
osx_image: xcode8 osx_image: xcode9
env: env:
- ACTION=test PLATFORM=Mac DESTINATION='platform=OS X' - ACTION=test PLATFORM=Mac DESTINATION='platform=OS X'

View File

@ -7,6 +7,7 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* 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 */; }; EE235F5F1C5785BC00C08960 /* Debugging.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F5E1C5785BC00C08960 /* Debugging.swift */; };
EE235F6D1C5785C600C08960 /* Constraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F621C5785C600C08960 /* Constraint.swift */; }; EE235F6D1C5785C600C08960 /* Constraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F621C5785C600C08960 /* Constraint.swift */; };
EE235F701C5785C600C08960 /* ConstraintDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F631C5785C600C08960 /* ConstraintDescription.swift */; }; EE235F701C5785C600C08960 /* ConstraintDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE235F631C5785C600C08960 /* ConstraintDescription.swift */; };
@ -46,6 +47,7 @@
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
2DBA080D1F1FAD66001CFED4 /* Typealiases.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Typealiases.swift; sourceTree = "<group>"; };
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; }; 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 = "<group>"; }; EE235F5E1C5785BC00C08960 /* Debugging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Debugging.swift; sourceTree = "<group>"; };
EE235F621C5785C600C08960 /* Constraint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constraint.swift; sourceTree = "<group>"; }; EE235F621C5785C600C08960 /* Constraint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constraint.swift; sourceTree = "<group>"; };
@ -178,6 +180,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
EE235F621C5785C600C08960 /* Constraint.swift */, EE235F621C5785C600C08960 /* Constraint.swift */,
2DBA080D1F1FAD66001CFED4 /* Typealiases.swift */,
EE235F631C5785C600C08960 /* ConstraintDescription.swift */, EE235F631C5785C600C08960 /* ConstraintDescription.swift */,
EE235F641C5785C600C08960 /* ConstraintInsets.swift */, EE235F641C5785C600C08960 /* ConstraintInsets.swift */,
EE235F651C5785C600C08960 /* ConstraintConfig.swift */, EE235F651C5785C600C08960 /* ConstraintConfig.swift */,
@ -373,6 +376,7 @@
EEF68FA61D784A5300980C26 /* ConstraintDSL.swift in Sources */, EEF68FA61D784A5300980C26 /* ConstraintDSL.swift in Sources */,
EE235FBB1C5785D400C08960 /* ConstraintMakerExtendable.swift in Sources */, EE235FBB1C5785D400C08960 /* ConstraintMakerExtendable.swift in Sources */,
EE235F881C5785C600C08960 /* ConstraintItem.swift in Sources */, EE235F881C5785C600C08960 /* ConstraintItem.swift in Sources */,
2DBA080E1F1FAD66001CFED4 /* Typealiases.swift in Sources */,
EE235F9A1C5785CE00C08960 /* ConstraintPriorityTarget.swift in Sources */, EE235F9A1C5785CE00C08960 /* ConstraintPriorityTarget.swift in Sources */,
EEF68FC01D7865AA00980C26 /* ConstraintLayoutSupport.swift in Sources */, EEF68FC01D7865AA00980C26 /* ConstraintLayoutSupport.swift in Sources */,
EEF68FB01D784FB100980C26 /* ConstraintLayoutGuide+Extensions.swift in Sources */, EEF68FB01D784FB100980C26 /* ConstraintLayoutGuide+Extensions.swift in Sources */,

View File

@ -89,7 +89,7 @@ public final class Constraint {
for layoutFromAttribute in layoutFromAttributes { for layoutFromAttribute in layoutFromAttributes {
// get layout to attribute // get layout to attribute
let layoutToAttribute: NSLayoutAttribute let layoutToAttribute: LayoutAttribute
#if os(iOS) || os(tvOS) #if os(iOS) || os(tvOS)
if layoutToAttributes.count > 0 { if layoutToAttributes.count > 0 {
if self.from.attributes == .edges && self.to.attributes == .margins { if self.from.attributes == .edges && self.to.attributes == .margins {
@ -166,7 +166,7 @@ public final class Constraint {
layoutConstraint.label = self.label layoutConstraint.label = self.label
// set priority // set priority
layoutConstraint.priority = UILayoutPriority(rawValue: self.priority.constraintPriorityTargetValue) layoutConstraint.priority = LayoutPriority(rawValue: self.priority.constraintPriorityTargetValue)
// set constraint // set constraint
layoutConstraint.constraint = self layoutConstraint.constraint = self
@ -244,7 +244,7 @@ public final class Constraint {
let requiredPriority = ConstraintPriority.required.value let requiredPriority = ConstraintPriority.required.value
if (layoutConstraint.priority.rawValue < requiredPriority), (self.priority.constraintPriorityTargetValue != requiredPriority) { if (layoutConstraint.priority.rawValue < requiredPriority), (self.priority.constraintPriorityTargetValue != requiredPriority) {
layoutConstraint.priority = UILayoutPriority(rawValue: self.priority.constraintPriorityTargetValue) layoutConstraint.priority = LayoutPriority(rawValue: self.priority.constraintPriorityTargetValue)
} }
} }
} }

View File

@ -103,8 +103,8 @@ internal struct ConstraintAttributes : OptionSet {
@available(iOS 8.0, *) @available(iOS 8.0, *)
internal static var centerWithinMargins: ConstraintAttributes { return self.init(786432) } internal static var centerWithinMargins: ConstraintAttributes { return self.init(786432) }
internal var layoutAttributes:[NSLayoutAttribute] { internal var layoutAttributes:[LayoutAttribute] {
var attrs = [NSLayoutAttribute]() var attrs = [LayoutAttribute]()
if (self.contains(ConstraintAttributes.left)) { if (self.contains(ConstraintAttributes.left)) {
attrs.append(.left) attrs.append(.left)
} }

View File

@ -42,7 +42,7 @@ extension ConstraintInsets: ConstraintConstantTarget {
extension ConstraintConstantTarget { extension ConstraintConstantTarget {
internal func constraintConstantTargetValueFor(layoutAttribute: NSLayoutAttribute) -> CGFloat { internal func constraintConstantTargetValueFor(layoutAttribute: LayoutAttribute) -> CGFloat {
if let value = self as? CGFloat { if let value = self as? CGFloat {
return value return value
} }

View File

@ -31,5 +31,5 @@
#if os(iOS) || os(tvOS) #if os(iOS) || os(tvOS)
public typealias ConstraintInsets = UIEdgeInsets public typealias ConstraintInsets = UIEdgeInsets
#else #else
public typealias ConstraintInsets = EdgeInsets public typealias ConstraintInsets = NSEdgeInsets
#endif #endif

View File

@ -33,7 +33,7 @@ internal enum ConstraintRelation : Int {
case lessThanOrEqual case lessThanOrEqual
case greaterThanOrEqual case greaterThanOrEqual
internal var layoutRelation: NSLayoutRelation { internal var layoutRelation: LayoutRelation {
get { get {
switch(self) { switch(self) {
case .equal: case .equal:

View File

@ -56,7 +56,7 @@ public struct ConstraintViewDSL: ConstraintAttributesDSL {
return self.view.contentHuggingPriority(for: .horizontal).rawValue return self.view.contentHuggingPriority(for: .horizontal).rawValue
} }
set { 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 return self.view.contentHuggingPriority(for: .vertical).rawValue
} }
set { 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 return self.view.contentCompressionResistancePriority(for: .horizontal).rawValue
} }
set { 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 return self.view.contentCompressionResistancePriority(for: .vertical).rawValue
} }
set { set {
self.view.setContentCompressionResistancePriority(UILayoutPriority(rawValue: newValue), for: .vertical) self.view.setContentCompressionResistancePriority(LayoutPriority(rawValue: newValue), for: .vertical)
} }
} }

View File

@ -77,7 +77,7 @@ public extension LayoutConstraint {
} }
private func descriptionForRelation(_ relation: NSLayoutRelation) -> String { private func descriptionForRelation(_ relation: LayoutRelation) -> String {
switch relation { switch relation {
case .equal: return "==" case .equal: return "=="
case .greaterThanOrEqual: 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) #if os(iOS) || os(tvOS)
switch attribute { switch attribute {
case .notAnAttribute: return "notAnAttribute" case .notAnAttribute: return "notAnAttribute"

22
Source/Typealiases.swift Normal file
View File

@ -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

View File

@ -395,7 +395,7 @@ class SnapKitTests: XCTestCase {
let constraints = view.snp_constraints as! [NSLayoutConstraint] let constraints = view.snp_constraints as! [NSLayoutConstraint]
// no guarantee which order the constraints are in, but we should test their couple // 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 heightWidth = (widthHeight.1, widthHeight.0)
let firstSecond = (constraints[0].firstAttribute.rawValue, constraints[1].firstAttribute.rawValue) 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") 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[0].constant, 50, "Should be 50")
XCTAssertEqual(constraints[1].constant, 50, "Should be 50") XCTAssertEqual(constraints[1].constant, 50, "Should be 50")
}
} }
func testConstraintIdentifier() { func testConstraintIdentifier() {
@ -436,8 +437,8 @@ class SnapKitTests: XCTestCase {
} }
func testEdgesToEdges() { func testEdgesToEdges() {
var fromAttributes = Set<NSLayoutAttribute>() var fromAttributes = Set<LayoutAttribute>()
var toAttributes = Set<NSLayoutAttribute>() var toAttributes = Set<LayoutAttribute>()
let view = View() let view = View()
self.container.addSubview(view) self.container.addSubview(view)