Skip to content

Commit

Permalink
fixed the compile time issues for OSX.
Browse files Browse the repository at this point in the history
  • Loading branch information
keshavvishwkarma committed Jun 10, 2017
1 parent 763bd9d commit 24bdd58
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
6 changes: 4 additions & 2 deletions KVConstraintKit/KVConstraintKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@

public typealias View = NSView
public typealias LayoutPriority = NSLayoutPriority
public typealias EdgeInsets = NSEdgeInsets
#if !swift(>=3.0)
public typealias EdgeInsets = NSEdgeInsets
#endif
#endif

extension EdgeInsets {
Expand Down Expand Up @@ -106,7 +108,7 @@ extension View {

#else
switch attr1 {
case .Right, .Trailing, .Bottom:
case .right, .trailing, .bottom:
return View.prepareConstraint(superview, attribute: attr1, secondView: self, attribute:attr2, relation: relation, multiplier:multiplier)
default: break
}
Expand Down
16 changes: 14 additions & 2 deletions KVConstraintKit/KVConstraintKitOperators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,24 @@ extension View : Modifiable { }

/// (containerView ~ (constraint, multiplier))
public func *(lhs: View, rhs: (NSLayoutConstraint, CGFloat)) {
(lhs ~ (rhs.0, rhs.0.modified(multiplier: rhs.1)))
#if os(iOS) || os(tvOS)
let constraint = rhs.0.modified(multiplier: rhs.1)
#else
guard let constraint = rhs.0.modified(multiplier: rhs.1) else { return }
#endif

(lhs ~ (rhs.0, constraint))

}

/// (containerView ~ (constraint, multiplier))
public func ~(lhs: View, rhs: (NSLayoutConstraint, NSLayoutRelation)) {
(lhs ~ (rhs.0, rhs.0.modified(relation: rhs.1)))
#if os(iOS) || os(tvOS)
let constraint = rhs.0.modified(relation: rhs.1)
#else
guard let constraint = rhs.0.modified(relation: rhs.1) else { return }
#endif
(lhs ~ (rhs.0, constraint))
}

/// (containerView ~ (old, new))
Expand Down
32 changes: 28 additions & 4 deletions KVConstraintKit/NSLayoutConstraintExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,48 @@ extension NSLayoutConstraint

}

#if os(iOS) || os(tvOS)

public final func modified(relation r: NSLayoutRelation) -> NSLayoutConstraint
{
if relation == r {
return self
}

return NSLayoutConstraint(item: firstItem, attribute: firstAttribute, relatedBy: r, toItem: secondItem, attribute: secondAttribute, multiplier: multiplier, constant: constant)
}

public final func modified(multiplier m: CGFloat) -> NSLayoutConstraint
{
if multiplier == m {
return self
}

return NSLayoutConstraint(item: firstItem, attribute: firstAttribute, relatedBy: relation, toItem: secondItem, attribute: secondAttribute, multiplier: m, constant: constant)
}

#else

public final func modified(relation r: NSLayoutRelation) -> NSLayoutConstraint?
{
if relation == r {
return self
}
guard let firstItem = self.firstItem else { return nil }
return NSLayoutConstraint(item: firstItem, attribute: firstAttribute, relatedBy: r, toItem: secondItem, attribute: secondAttribute, multiplier: multiplier, constant: constant)
}

public final func modified(multiplier m: CGFloat) -> NSLayoutConstraint?
{
if multiplier == m {
return self
}
guard let firstItem = self.firstItem else { return nil }
return NSLayoutConstraint(item: firstItem, attribute: firstAttribute, relatedBy: relation, toItem: secondItem, attribute: secondAttribute, multiplier: m, constant: constant)
}

#endif



final func isSelfConstraint() -> Bool
{
// For aspect Ratio
Expand All @@ -139,7 +163,7 @@ extension Array where Element: NSLayoutConstraint
!( $0.firstItem is UILayoutSupport || $0.secondItem is UILayoutSupport)
}
#else
let reverseConstraints = reverse()
let reverseConstraints = reversed()
#endif

return reverseConstraints.filter {
Expand Down

0 comments on commit 24bdd58

Please sign in to comment.