<commit_before>//
//  ZLSwipeableView.swift
//  ZLSwipeableViewSwiftDemo
//
//  Created by <NAME> on 4/27/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import UIKit

// MARK: - Helper classes
public typealias ZLSwipeableViewDirection = Direction

public func ==(lhs: Direction, rhs: Direction) -> Bool {
    return lhs.rawValue == rhs.rawValue
}

/**
*  Swiped direction.
*/
public struct Direction : OptionSetType, CustomStringConvertible {

    public var rawValue: UInt

    public init(rawValue: UInt) {
        self.rawValue = rawValue
    }

    public static let None = Direction(rawValue: 0b0000)
    public static let Left = Direction(rawValue: 0b0001)
    public static let Right = Direction(rawValue: 0b0010)
    public static let Up = Direction(rawValue: 0b0100)
    public static let Down = Direction(rawValue: 0b1000)
    public static let Horizontal: Direction = [Left, Right]
    public static let Vertical: Direction = [Up, Down]
    public static let All: Direction = [Horizontal, Vertical]

    public static func fromPoint(point: CGPoint) -> Direction {
        switch (point.x, point.y) {
        case let (x, y) where abs(x) >= abs(y) && x > 0:
            return .Right
        case let (x, y) where abs(x) >= abs(y) && x < 0:
            return .Left
        case let (x, y) where abs(x) < abs(y) && y < 0:
            return .Up
        case let (x, y) where abs(x) < abs(y) && y > 0:
            return .Down
        case (_, _):
            return .None
        }
    }

    public var description: String {
        switch self {
        case Direction.None:
            return "None"
        case Direction.Left:
            return "Left"
        case Direction.Right:
            return "Right"
        case Direction.Up:
            return "Up"
        case Direction.Down:
            return "Down"
        case Direction.Horizontal:
            return "Horizontal"
        case Direction.Vertical:
            return "Vertical"
        case Direction.All:
            return "All"
        default:
            return "Unknown"
        }
    }

}

// data source
public typealias NextViewHandler = () -> UIView?
public typealias PreviousViewHandler = () -> UIView?

// customization
public typealias AnimateViewHandler = (view: UIView, index: Int, views: [UIView], swipeableView: ZLSwipeableView) -> ()
public typealias InterpretDirectionHandler = (topView: UIView, direction: Direction, views: [UIView], swipeableView: ZLSwipeableView) -> (CGPoint, CGVector)
public typealias ShouldSwipeHandler = (view: UIView, movement: Movement, swipeableView: ZLSwipeableView) -> Bool

// delegates
public typealias DidStartHandler = (view: UIView, atLocation: CGPoint) -> ()
public typealias SwipingHandler = (view: UIView, atLocation: CGPoint, translation: CGPoint) -> ()
public typealias DidEndHandler = (view: UIView, atLocation: CGPoint) -> ()
public typealias DidSwipeHandler = (view: UIView, inDirection: Direction, directionVector: CGVector) -> ()
public typealias DidCancelHandler = (view: UIView) -> ()

public struct Movement {
    let location: CGPoint
    let translation: CGPoint
    let velocity: CGPoint
}

// MARK: - Main
public class ZLSwipeableView: UIView {

    // MARK: Data Source
    public var numberOfActiveView = UInt(4)
    public var nextView: NextViewHandler? {
        didSet {
            loadViews()
        }
    }
    public var previousView: PreviousViewHandler?
    // Rewinding
    public var history = [UIView]()
    public var numberOfHistoryItem = UInt(10)

    // MARK: Customizable behavior
    public var animateView = ZLSwipeableView.defaultAnimateViewHandler()
    public var interpretDirection = ZLSwipeableView.defaultInterpretDirectionHandler()
    public var shouldSwipeView = ZLSwipeableView.defaultShouldSwipeViewHandler()
    public var minTranslationInPercent = CGFloat(0.25)
    public var minVelocityInPointPerSecond = CGFloat(750)
    public var allowedDirection = Direction.Horizontal

    // MARK: Delegate
    public var didStart: DidStartHandler?
    public var swiping: SwipingHandler?
    public var didEnd: DidEndHandler?
    public var didSwipe: DidSwipeHandler?
    public var didCancel: DidCancelHandler?

    // MARK: Private properties
    /// Contains subviews added by the user.
    private var containerView = UIView()

    /// Contains auxiliary subviews.
    private var miscContainerView = UIView()

    private var animator: UIDynamicAnimator!

    private var viewManagers = [UIView: ViewManager]()

    private var scheduler = Scheduler()

    // MARK: Life cycle
    override init(frame: CGRect) {
        super.init(frame: frame)
        setup()
    }

    required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setup()
    }

    private func setup() {
        addSubview(containerView)
        addSubview(miscContainerView)
        animator = UIDynamicAnimator(referenceView: self)
    }

    deinit {
        nextView = nil

        didStart = nil
        swiping = nil
        didEnd = nil
        didSwipe = nil
        didCancel = nil
    }
<commit_msg>Add public modifier to initWithFrame<commit_after>//
//  ZLSwipeableView.swift
//  ZLSwipeableViewSwiftDemo
//
//  Created by <NAME> on 4/27/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import UIKit

// MARK: - Helper classes
public typealias ZLSwipeableViewDirection = Direction

public func ==(lhs: Direction, rhs: Direction) -> Bool {
    return lhs.rawValue == rhs.rawValue
}

/**
*  Swiped direction.
*/
public struct Direction : OptionSetType, CustomStringConvertible {

    public var rawValue: UInt

    public init(rawValue: UInt) {
        self.rawValue = rawValue
    }

    public static let None = Direction(rawValue: 0b0000)
    public static let Left = Direction(rawValue: 0b0001)
    public static let Right = Direction(rawValue: 0b0010)
    public static let Up = Direction(rawValue: 0b0100)
    public static let Down = Direction(rawValue: 0b1000)
    public static let Horizontal: Direction = [Left, Right]
    public static let Vertical: Direction = [Up, Down]
    public static let All: Direction = [Horizontal, Vertical]

    public static func fromPoint(point: CGPoint) -> Direction {
        switch (point.x, point.y) {
        case let (x, y) where abs(x) >= abs(y) && x > 0:
            return .Right
        case let (x, y) where abs(x) >= abs(y) && x < 0:
            return .Left
        case let (x, y) where abs(x) < abs(y) && y < 0:
            return .Up
        case let (x, y) where abs(x) < abs(y) && y > 0:
            return .Down
        case (_, _):
            return .None
        }
    }

    public var description: String {
        switch self {
        case Direction.None:
            return "None"
        case Direction.Left:
            return "Left"
        case Direction.Right:
            return "Right"
        case Direction.Up:
            return "Up"
        case Direction.Down:
            return "Down"
        case Direction.Horizontal:
            return "Horizontal"
        case Direction.Vertical:
            return "Vertical"
        case Direction.All:
            return "All"
        default:
            return "Unknown"
        }
    }

}

// data source
public typealias NextViewHandler = () -> UIView?
public typealias PreviousViewHandler = () -> UIView?

// customization
public typealias AnimateViewHandler = (view: UIView, index: Int, views: [UIView], swipeableView: ZLSwipeableView) -> ()
public typealias InterpretDirectionHandler = (topView: UIView, direction: Direction, views: [UIView], swipeableView: ZLSwipeableView) -> (CGPoint, CGVector)
public typealias ShouldSwipeHandler = (view: UIView, movement: Movement, swipeableView: ZLSwipeableView) -> Bool

// delegates
public typealias DidStartHandler = (view: UIView, atLocation: CGPoint) -> ()
public typealias SwipingHandler = (view: UIView, atLocation: CGPoint, translation: CGPoint) -> ()
public typealias DidEndHandler = (view: UIView, atLocation: CGPoint) -> ()
public typealias DidSwipeHandler = (view: UIView, inDirection: Direction, directionVector: CGVector) -> ()
public typealias DidCancelHandler = (view: UIView) -> ()

public struct Movement {
    let location: CGPoint
    let translation: CGPoint
    let velocity: CGPoint
}

// MARK: - Main
public class ZLSwipeableView: UIView {

    // MARK: Data Source
    public var numberOfActiveView = UInt(4)
    public var nextView: NextViewHandler? {
        didSet {
            loadViews()
        }
    }
    public var previousView: PreviousViewHandler?
    // Rewinding
    public var history = [UIView]()
    public var numberOfHistoryItem = UInt(10)

    // MARK: Customizable behavior
    public var animateView = ZLSwipeableView.defaultAnimateViewHandler()
    public var interpretDirection = ZLSwipeableView.defaultInterpretDirectionHandler()
    public var shouldSwipeView = ZLSwipeableView.defaultShouldSwipeViewHandler()
    public var minTranslationInPercent = CGFloat(0.25)
    public var minVelocityInPointPerSecond = CGFloat(750)
    public var allowedDirection = Direction.Horizontal

    // MARK: Delegate
    public var didStart: DidStartHandler?
    public var swiping: SwipingHandler?
    public var didEnd: DidEndHandler?
    public var didSwipe: DidSwipeHandler?
    public var didCancel: DidCancelHandler?

    // MARK: Private properties
    /// Contains subviews added by the user.
    private var containerView = UIView()

    /// Contains auxiliary subviews.
    private var miscContainerView = UIView()

    private var animator: UIDynamicAnimator!

    private var viewManagers = [UIView: ViewManager]()

    private var scheduler = Scheduler()

    // MARK: Life cycle
    public override init(frame: CGRect) {
        super.init(frame: frame)
        setup()
    }

    required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setup()
    }

    private func setup() {
        addSubview(containerView)
        addSubview(miscContainerView)
        animator = UIDynamicAnimator(referenceView: self)
    }

    deinit {
        nextView = nil

        didStart = nil
        swiping = nil
        didEnd = nil
        didSwipe = nil
        didCancel = nil
    }

{'fraction_non_alphanumeric': 0.09307317073170732, 'fraction_numerical': 0.009170731707317073, 'mean_word_length': 2.7087554269175107, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6634841', 'n_tokens_mistral': 3135, 'n_tokens_neox': 2930, 'n_words': 895}