 
 public class PullToRefreshView: UIView {
     
-    var previousOffset: CGFloat?
+    var previousOffset: CGFloat = 0
     var pullToRefreshAction: (() -> ())
     var label: UILabel = UILabel()
     var activityIndicator: UIActivityIndicatorView

        var insets = scrollView.contentInset
        
        // we need to restore previous offset because we will animate scroll view insets and regular scroll view animating is not applied then
        scrollView.contentOffset.y = previousOffset!
        scrollView.bounces = false
        UIView.animateWithDuration(0.3, delay: 0, options:nil, animations: {
            scrollView.contentInset = UIEdgeInsets(top: 50, left: insets.left, bottom: insets.bottom, right: insets.right)

                var scrollView = object as? UIScrollView
                if (scrollView != nil) {
                    println(scrollView?.contentOffset.y)
                    if (previousOffset < -pullToRefreshDefaultHeight) {
                        label.text = "release to refresh"
                        if (scrollView?.dragging == false && loading == false) {
                            loading = true
