Created
February 26, 2015 01:07
-
-
Save mgp/650573cfae116e1b4fca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
A UIAlertView that owns its delegate so that the client that displays the UIAlertView | |
does not need to own it. | |
This is useful when the client that displays the UIAlertView is not the UIAlertDelegate | |
implementation. It is free to initialize an object to serve as the delegate that exists | |
only for the lifetime of the UIAlertView, thereby fostering decomposition. | |
*/ | |
class OwnedDelegateAlertView: UIAlertView { | |
private let ownedDelegate: AnyObject? | |
override init(title: String?, message: String?, delegate: AnyObject?, cancelButtonTitle: String?) { | |
ownedDelegate = delegate | |
super.init(title: title, message: message, delegate: delegate, cancelButtonTitle: cancelButtonTitle) | |
} | |
convenience init(title: String, message: String, delegate: UIAlertViewDelegate, cancelButtonTitle: String, otherButtonTitles firstButtonTitle: String, _ moreButtonTitles: String...) { | |
self.init(title: title, message: message, delegate: delegate, cancelButtonTitle: cancelButtonTitle) | |
addButtonWithTitle(firstButtonTitle) | |
moreButtonTitles.each { self.addButtonWithTitle($0); return } | |
} | |
required init(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
override init(frame: CGRect) { super.init(frame: frame) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment