Skip to content

Commit

Permalink
Fix memory leaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
zelic91 committed Dec 21, 2016
1 parent bf488f5 commit 5679fb2
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions Pod/Classes/ZAlertView.swift
Original file line number Diff line number Diff line change
@@ -113,11 +113,12 @@ import UIKit

open var allowTouchOutsideToDismiss: Bool = true {
didSet {
weak var weakSelf = self
if allowTouchOutsideToDismiss == false {
self.tapOutsideTouchGestureRecognizer.removeTarget(self, action: #selector(ZAlertView.dismissAlertView))
weakSelf?.tapOutsideTouchGestureRecognizer.removeTarget(weakSelf, action: #selector(ZAlertView.dismissAlertView))
}
else {
self.tapOutsideTouchGestureRecognizer.addTarget(self, action: #selector(ZAlertView.dismissAlertView))
weakSelf?.tapOutsideTouchGestureRecognizer.addTarget(weakSelf, action: #selector(ZAlertView.dismissAlertView))
}
}
}
@@ -532,12 +533,13 @@ import UIKit
}

open func addButton(_ title: String, font: UIFont, color: UIColor?, titleColor: UIColor?, touchHandler: @escaping TouchHandler) {
weak var weakSelf = self
let button = ZButton(touchHandler: touchHandler)
button.setTitle(title, for: UIControlState())
button.color = color
button.titleColor = titleColor
button.titleLabel?.font = font
button.addTarget(self, action: #selector(ZAlertView.buttonDidTouch(_:)), for: UIControlEvents.touchUpInside)
button.addTarget(weakSelf!, action: #selector(ZAlertView.buttonDidTouch(_:)), for: UIControlEvents.touchUpInside)
buttons.append(button)
self.alertView.addSubview(button)
}
@@ -549,8 +551,11 @@ import UIKit
}

func buttonDidTouch(_ sender: ZButton) {
weak var weakSelf = self
if let listener = sender.touchHandler {
listener(self)
if (weakSelf != nil) {
listener(weakSelf!)
}
}
}

@@ -839,7 +844,8 @@ import UIKit
var color: UIColor?
var titleColor: UIColor? {
didSet {
self.setTitleColor(titleColor, for: UIControlState())
weak var weakSelf = self
weakSelf?.setTitleColor(titleColor, for: UIControlState())
}
}

2 changes: 1 addition & 1 deletion ZAlertView.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ZAlertView"
s.version = "0.3.3"
s.version = "0.3.4"
s.summary = "A customizable AlertView written in Swift."
s.description = <<-DESC
A customizable AlertView written in Swift as a present for my 26th birthday. Of course, current libraries don't fit my need, so I have to rewrite one for later extensibility.

0 comments on commit 5679fb2

Please sign in to comment.