Skip to content

Commit

Permalink
Extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
RamblinWreck77 authored Feb 7, 2019
1 parent 5bf2ad4 commit ff51204
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
26 changes: 23 additions & 3 deletions Sources/Pageboy/Utilities/Extensions/UIView+AutoLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ internal extension UIView {

@discardableResult
func pinToSuperviewEdges(priority: UILayoutPriority = .required) -> [NSLayoutConstraint] {
let superview = guardForSuperview()
guard let superview = guardForSuperview() else {
#if DEBUG
fatalError("Could not fetch superview in pinToSuperviewEdges")
#else
return [NSLayoutConstraint]()
#endif
}



return addConstraints(priority: priority, { () -> [NSLayoutConstraint] in
return [
Expand All @@ -38,14 +46,18 @@ internal extension UIView {
})

guard let constraint = constraints.first else {
#if DEBUG
fatalError("Could not add matchWidth constraint")
#else
return nil
#endif
}
return constraint
}

@discardableResult
func matchHeight(to view: UIView,
priority: UILayoutPriority = .required) -> NSLayoutConstraint {
priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
let constraints = addConstraints(priority: priority, { () -> [NSLayoutConstraint] in
return [NSLayoutConstraint(item: self,
attribute: .height,
Expand All @@ -57,7 +69,11 @@ internal extension UIView {
})

guard let constraint = constraints.first else {
#if DEBUG
fatalError("Could not add matchHeight constraint")
#else
return nil
#endif
}
return constraint
}
Expand All @@ -79,9 +95,13 @@ internal extension UIView {
return constraints
}

private func guardForSuperview() -> UIView {
private func guardForSuperview() -> UIView? {
guard let superview = superview else {
#if DEBUG
fatalError("No superview for view \(self)")
#else
return nil
#endif
}
return superview
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ extension UIView {
assert(Thread.isMainThread)
return UIView.userInterfaceLayoutDirection(for: semanticContentAttribute)
}

}

0 comments on commit ff51204

Please sign in to comment.