      */
     public func setOn(isOn: Bool, animated: Bool) {
         switchValue = isOn
-        
-        if on {
-            showOn(animated)
-        }
-        else {
-            showOff(animated)
-        }
+        on ? showOn(animated: animated) : showOff(animated: animated)
     }
     
     /**
      *   Detects whether the switch is on or off
      *
-     *	 @return	Bool true if switch is on, false otherwise
-     */
-    public func isOn() -> Bool {
+     *     @return    Bool true if switch is on, false otherwise
+     */
+    public var isOn: Bool {
         return on
     }
     
     // MARK: - Private methods -
-
+    
     /**
      *   Updates the looks of the switch to be in the on position
      *   optionally make it animated
      */
     private func showOn(animated: Bool) {
-        thumbView.endTracking(true)
-
-        UIView.animateWithDuration(animationDuration, delay: 0.0, options: [UIViewAnimationOptions.CurveEaseIn, UIViewAnimationOptions.BeginFromCurrentState], animations: {
-            self.thumbView.frame = CGRectOffset(self.originalThumbRect, self.maxThumbOffset, 0)
-        }, completion: nil)
+        thumbView.endTracking(isOn: true)
+        
+        UIView.animate(withDuration: animated ? animationDuration : 0, delay: 0, options: [.curveEaseIn, .beginFromCurrentState], animations: {
+            self.thumbView.frame = self.originalThumbRect.offsetBy(dx: self.maxThumbOffset, dy: 0)
+        })
     }
     
     /**

import QuartzCore
import UIKit

internal let defaultFrame = CGRectMake(0, 0, 50, 30)
internal let borderMargin = CGFloat(17)
internal let animationDuration = CFTimeInterval(0.3)

@IBDesignable @objc public class PMZSwitch : UIControl, UIGestureRecognizerDelegate {

    // MARK: - Properties -
    // MARK: public
    /**
     *   Set (without animation) whether the switch is on or off
     */
    @IBInspectable public var on: Bool {
        get {
            return switchValue
        }
        set {
            switchValue = newValue
            self.setOn(newValue, animated: false)
        }
    }
    
    @IBInspectable public var thumbTintColor: UIColor {
        get {
            return thumbView.thumbTintColor
        }
        set {
            thumbView.thumbTintColor = newValue
        }
    }
    
    @IBInspectable public var onThumbTintColor: UIColor {
        get {
            return thumbView.onThumbTintColor
        }
        set {
            thumbView.onThumbTintColor = newValue
        }
    }
    
    @IBInspectable public var shadowColor: UIColor {
        get {
            return thumbView.shadowColor
        }
        set {
            thumbView.shadowColor = newValue
        }
    }
    
    // MARK: internal

        
        on = false
        
        tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture(_:)))
        tapGestureRecognizer.delegate = self
        self.addGestureRecognizer(tapGestureRecognizer)
    }
    
    // MARK: - Tap gesture recognizer handler -
    
    @objc func handleTapGesture(_ gestureRecognizer: UITapGestureRecognizer) {
        guard !ignoreTap else { return }
        
        if gestureRecognizer.state == .ended {
            thumbView.toggle(animated: true)
            setOn(isOn: !on, animated: true)
        }
    }
    
    // MARK: - UIControl tracking methods -
    
    override public func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool {
        super.beginTracking(touch, with: event)
        
        startTrackingPoint = touch.location(in: self)
        startThumbFrame = thumbView.frame
        thumbView.startTracking()
        
        return true
    }
    
    override public func continueTracking(_ touch: UITouch, with event: UIEvent?) -> Bool {
        super.continueTracking(touch, with: event)
        ignoreTap = true
        
        // Get touch location
        let lastPoint = touch.location(in: self)
        let thumbMinPosition = originalThumbRect.origin.x
        let thumbMaxPosition = originalThumbRect.origin.x + maxThumbOffset
        let touchXOffset = lastPoint.x - startTrackingPoint.x
        
        var desiredFrame = startThumbFrame.offsetBy(dx: touchXOffset, dy: 0)
        desiredFrame.origin.x = min(max(desiredFrame.origin.x, thumbMinPosition), thumbMaxPosition)
        thumbView.frame = desiredFrame
        
        //                                 // right -> left
        thumbView.animationProgress = on ? (thumbMaxPosition - desiredFrame.origin.x) / maxThumbOffset :
            //                             // left -> right
            (desiredFrame.origin.x - thumbMinPosition) / maxThumbOffset
        
        return true
    }
    
    override public func endTracking(_ touch: UITouch?, with event: UIEvent?) {
        super.endTracking(touch, with: event)
        
        thumbView.center.x > self.bounds.midX ? setOn(isOn: true, animated: true) : setOn(isOn: false, animated: true)
        
        ignoreTap = false
    }
    
    override public func cancelTracking(with event: UIEvent?) {
        super.cancelTracking(with: event)
        guard ignoreTap else { return }
        
        // just animate back to the original value
        on ? showOn(animated: true) : showOff(animated: true)
        ignoreTap = false
    }
    
