     
     // MARK: Managing Arranged Views
     
+    /**
+    Adds a view to the end of the arrangedSubviews array.
+    
+    The stack view ensures that the arrangedSubviews array is always a subset of its subviews array. This method automatically adds the provided view as a subview of the stack view, if it is not already. If the view is already a subview, this operation does not alter the subview ordering.
+    */
     public func addArrangedSubview(view: UIView) {
         insertArrangedSubview(view, atIndex: arrangedSubviews.count)
     }
-
+    
+    /**
+     Removes the provided view from the stack’s array of arranged subviews.
+     
+     This method removes the provided view from the stack’s arrangedSubviews array. The view’s position and size will no longer be managed by the stack view. However, this method does not remove the provided view from the stack’s subviews array; therefore, the view is still displayed as part of the view hierarchy.
+     */
     public func removeArrangedSubview(view: UIView) {
         if let index = arrangedSubviews.indexOf(view) {
             arrangedSubviews.removeAtIndex(index)

    
    // MARK: Layout
    
    public func invalidateLayout() {
        if !invalidated {
            invalidated = true


import UIKit

/** The layout that defines the size and position of the arranged views along the stack view’s axis.
*/
public enum StackViewDistribution {
    /** A layout where the stack view resizes its arranged views so that they fill the available space along the stack view’s axis.
     */
    case Fill
    
    /** A layout where the stack view resizes its arranged views so that they fill the available space along the stack view’s axis. The views are resized so that they are all the same size along the stack view’s axis.
     */
    case FillEqually
    
    /** A layout where the stack view resizes its arranged views so that they fill the available space along the stack view’s axis. Views are resized proportionally based on their intrinsic content size along the stack view’s axis.
     */
    case FillProportionally
    
    /** A layout where the stack view positions its arranged views so that they fill the available space along the stack view’s axis. When the arranged views do not fill the stack view, it pads the spacing between the views evenly.
     */
    case EqualSpacing
    
    /** A layout that attempts to position the arranged views so that they have an equal center-to-center spacing along the stack view’s axis, while maintaining the spacing property’s distance between views.
     */
    case EqualCentering
}


/** Alignment—the layout transverse to the stacking axis.
 */
public enum StackViewAlignment {
    /** A layout where the stack view resizes its arranged views so that they fill the available space perpendicular to the stack view’s axis.
     */
    case Fill
    
    /** A layout for vertical stacks where the stack view aligns the leading edge of its arranged views along its leading edge. This is equivalent to the `StackViewAlignment.Top` alignment for horizontal stacks.
     */
    case Leading
    
    /** A layout for horizontal stacks where the stack view aligns the top edge of its arranged views along its top edge. This is equivalent to the `StackViewAlignment.Leading` alignment for vertical stacks.
     */
    public static var Top: StackViewAlignment {
        return .Leading
    }
    
    /** A layout where the stack view aligns its arranged views based on their first baseline. This alignment is only valid for horizontal stacks.
     */
    case FirstBaseline
    
    /** A layout where the stack view aligns the center of its arranged views with its center along its axis.
     */
    case Center
    
    /** A layout for vertical stacks where the stack view aligns the trailing edge of its arranged views along its trailing edge. This is equivalent to the `StackViewAlignment.Bottom` alignment for horizontal stacks.
     */
    case Trailing
    
    /** A layout for horizontal stacks where the stack view aligns the bottom edge of its arranged views along its bottom edge. This is equivalent to the `StackViewAlignment.Trailing` alignment for vertical stacks.
     */
    public static var Bottom: StackViewAlignment {
        return .Trailing
    }
    
    /** A layout where the stack view aligns its arranged views based on their last baseline. This alignment is only valid for horizontal stacks.
     */
    case LastBaseline
}

/**
The StackView class provides a streamlined interface for laying out a collection of views in either a column or a row. Stack views let you leverage the power of Auto Layout, creating user interfaces that can dynamically adapt to the device’s orientation, screen size, and any changes in the available space. The stack view manages the layout of all the views in its `arrangedSubviews` property. These views are arranged along the stack view’s `axis`, based on their order in the `arrangedSubviews` array. The exact layout varies depending on the stack view’s `axis`, `distribution`, `alignment`, `spacing`, and other properties.
 
 See UIStackView documentation for more info.
*/
public class StackView : UIView {
    
    /// The axis along which the arranged views are laid out.
    public var axis: UILayoutConstraintAxis = .Horizontal {
        didSet { if axis != oldValue { invalidateLayout() } }
    }
    
    /// The distribution of the arranged views along the stack view’s axis.
    public var distribution: StackViewDistribution = .Fill {
        didSet { if distribution != oldValue { invalidateLayout() } }
    }
    
    /// The alignment of the arranged subviews perpendicular to the stack view’s axis.
    public var alignment: StackViewAlignment = .Fill {
        didSet { if alignment != oldValue { invalidateLayout() } }
    }
    
    /// The distance in points between the adjacent edges of the stack view’s arranged views.
    public var spacing: CGFloat = 0.0 {
        didSet { if spacing != oldValue { invalidateLayout() } }
    }
    
    /// A Boolean value that determines whether the vertical spacing between views is measured from their baselines.
    public var baselineRelativeArrangement = false {
        didSet { if baselineRelativeArrangement != oldValue { invalidateLayout() } }
    }
    
    /// A Boolean value that determines whether the stack view lays out its arranged views relative to its layout margins.
    public var layoutMarginsRelativeArrangement = false {
        didSet { if layoutMarginsRelativeArrangement != oldValue { invalidateLayout() } }
    }

    /// The list of views arranged by the stack view.
    public private(set) var arrangedSubviews = [UIView]()
    
    private var alignmentArrangement: AlignedLayoutArrangement!
    private var distributionArrangement: DistributionLayoutArrangement!
    private var invalidated = false
    private var hiddenViews = Set<UIView>()
    
    /// Returns a new stack view object that manages the provided views.
    public init(arrangedSubviews views: [UIView]) {
        super.init(frame: CGRectZero)
        commonInit(views: views)
    }

    /// Returns a new stack view object.
    public convenience init() {
        self.init(arrangedSubviews: [])
    }
    
    /// Returns a new stack view object.
    public required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        commonInit(views: [])
    }
    
    private func commonInit(views views: [UIView]) {
