 import UIKit
 
-public struct EdgeAnchor: OptionSetType {
+public struct EdgeAnchor: OptionSet {
     public let rawValue: Int
     public let constant: CGFloat
     public let priority: UILayoutPriority

public extension NSLayoutConstraint {

    static func activateAllConstraints(constraints: [[NSLayoutConstraint]]) {
        NSLayoutConstraint.activateConstraints(constraints.flatMap { $0 })
    }

    static func deactivateAllConstraints(constraints: [[NSLayoutConstraint]]) {
        NSLayoutConstraint.deactivateConstraints(constraints.flatMap { $0 })
    }

}


// MARK: Objective-C API

public extension UIView {

    @available(*, unavailable, message="Only to be used from Objective-C") func objc_pinToView(view: UIView, inset: UIEdgeInsets = UIEdgeInsetsZero) -> [NSLayoutConstraint] {
        return self._objcPinToView(view)
    }

    @available(*, unavailable, message="Only to be used from Objective-C") func objc_pinToSuperview(inset: UIEdgeInsets = UIEdgeInsetsZero) -> [NSLayoutConstraint] {
        if let superview = self.superview {
            return self._objcPinToView(superview, inset: inset)
        } else {
            fatalError("Cannot pin to a nil superview")
        }
    }

}



public extension UIView {

    func pinToSuperview(edges: [EdgeAnchor] = EdgeAnchor.allSides, relation: NSLayoutRelation = .equal, activate: Bool = true) -> [NSLayoutConstraint] {
        if let superview = self.superview {
            return self.pinToView(view: superview, edges: edges, activate: activate)
        } else {
            fatalError("Cannot pin to a nil superview")
        }
    }

    func pinToView(view: UIView, edges: [EdgeAnchor] = EdgeAnchor.allSides, relation: NSLayoutRelation = .equal, activate: Bool = true) -> [NSLayoutConstraint] {
        let addConstraint: (_ edge: EdgeAnchor) -> NSLayoutConstraint? = { edge in
            if edges.contains(edge) {
                let constant: CGFloat
                let priority: UILayoutPriority

                if let index = edges.index(of: edge) {
                    let currentEdge = edges[index]
                    constant = currentEdge.constant
                    priority = currentEdge.priority
