Skip to content

Commit 54cd8ae

Browse files
committed
Init methods replaced with class methods
1 parent af1773b commit 54cd8ae

11 files changed

Lines changed: 127 additions & 122 deletions

File tree

CFAlertViewController.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "CFAlertViewController"
19-
s.version = "2.0.2"
19+
s.version = "2.0.3"
2020
s.summary = "CFAlertViewController is a library that helps you display and customise alerts and action sheets on iPad and iPhone."
2121

2222
# This description is used to generate tags and improve search results.
@@ -79,7 +79,7 @@ Pod::Spec.new do |s|
7979
# Supports git, hg, bzr, svn and HTTP.
8080
#
8181

82-
s.source = { :git => "https://github.com/Codigami/CFAlertViewController.git", :tag => "v2.0.2" }
82+
s.source = { :git => "https://github.com/Codigami/CFAlertViewController.git", :tag => "v2.0.3" }
8383

8484

8585
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

CFAlertViewController/CFAlertViewController.swift

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import UIKit
1111

1212
@objc(CFAlertViewController)
1313
public class CFAlertViewController: UIViewController {
14-
14+
1515
// MARK: - Declarations
1616
public typealias CFAlertViewControllerDismissBlock = (_ isBackgroundTapped: Bool) -> ()
1717

@@ -78,7 +78,7 @@ public class CFAlertViewController: UIViewController {
7878
internal var messageString: String?
7979
internal var actionList = [CFAlertAction]()
8080
internal var dismissHandler: CFAlertViewControllerDismissBlock?
81-
private var keyboardHeight: CGFloat = 0.0 {
81+
internal var keyboardHeight: CGFloat = 0.0 {
8282

8383
didSet {
8484

@@ -90,57 +90,59 @@ public class CFAlertViewController: UIViewController {
9090
}
9191
}
9292
}
93-
private var tapGesture: UITapGestureRecognizer!
93+
internal var tapGesture: UITapGestureRecognizer!
9494

95-
@IBOutlet private weak var mainViewBottomConstraint: NSLayoutConstraint?
96-
@IBOutlet private weak var tableView: UITableView?
97-
@IBOutlet private weak var containerViewCenterYConstraint: NSLayoutConstraint?
98-
@IBOutlet private weak var containerViewBottomConstraint: NSLayoutConstraint?
99-
@IBOutlet private weak var tableViewHeightConstraint: NSLayoutConstraint?
95+
@IBOutlet internal weak var mainViewBottomConstraint: NSLayoutConstraint?
96+
@IBOutlet internal weak var tableView: UITableView?
97+
@IBOutlet internal weak var containerViewCenterYConstraint: NSLayoutConstraint?
98+
@IBOutlet internal weak var containerViewBottomConstraint: NSLayoutConstraint?
99+
@IBOutlet internal weak var tableViewHeightConstraint: NSLayoutConstraint?
100100

101101

102102
// MARK: - Initialisation Method
103-
convenience public init(title: String?,
104-
message: String?,
105-
textAlignment: NSTextAlignment,
106-
preferredStyle: CFAlertControllerStyle,
107-
didDismissAlertHandler dismiss: CFAlertViewControllerDismissBlock?) {
103+
public class func alert(title: String?,
104+
message: String?,
105+
textAlignment: NSTextAlignment,
106+
preferredStyle: CFAlertControllerStyle,
107+
didDismissAlertHandler dismiss: CFAlertViewControllerDismissBlock?) -> CFAlertViewController {
108108

109-
self.init(title: title,
110-
message: message,
111-
textAlignment: textAlignment,
112-
preferredStyle: preferredStyle,
113-
headerView: nil,
114-
footerView: nil,
115-
didDismissAlertHandler: dismiss)
116-
}
117-
118-
convenience public init(title: String?,
119-
message: String?,
120-
textAlignment: NSTextAlignment,
121-
preferredStyle: CFAlertControllerStyle,
122-
headerView: UIView?,
123-
footerView: UIView?,
124-
didDismissAlertHandler dismiss: CFAlertViewControllerDismissBlock?) {
109+
return CFAlertViewController.alert(title: title,
110+
message: message,
111+
textAlignment: textAlignment,
112+
preferredStyle: preferredStyle,
113+
headerView: nil,
114+
footerView: nil,
115+
didDismissAlertHandler: dismiss)
116+
}
117+
118+
public class func alert(title: String?,
119+
message: String?,
120+
textAlignment: NSTextAlignment,
121+
preferredStyle: CFAlertControllerStyle,
122+
headerView: UIView?,
123+
footerView: UIView?,
124+
didDismissAlertHandler dismiss: CFAlertViewControllerDismissBlock?) -> CFAlertViewController {
125125

126126
// Get Current Bundle
127127
let bundle = Bundle(for: CFAlertViewController.self)
128128

129129
// Create New Instance Of Alert Controller
130-
self.init(nibName: "CFAlertViewController", bundle: bundle)
130+
let alert = CFAlertViewController.init(nibName: "CFAlertViewController", bundle: bundle)
131131

132132
// Assign Properties
133-
self.titleString = title
134-
self.messageString = message
135-
self.textAlignment = textAlignment
136-
self.preferredStyle = preferredStyle
137-
self.setHeaderView(headerView, shouldUpdateContainerFrame: false, withAnimation: false)
138-
self.setFooterView(footerView, shouldUpdateContainerFrame: false, withAnimation: false)
139-
self.dismissHandler = dismiss
133+
alert.titleString = title
134+
alert.messageString = message
135+
alert.textAlignment = textAlignment
136+
alert.preferredStyle = preferredStyle
137+
alert.setHeaderView(headerView, shouldUpdateContainerFrame: false, withAnimation: false)
138+
alert.setFooterView(footerView, shouldUpdateContainerFrame: false, withAnimation: false)
139+
alert.dismissHandler = dismiss
140140

141141
// Custom Presentation
142-
modalPresentationStyle = .custom
143-
transitioningDelegate = self
142+
alert.modalPresentationStyle = .custom
143+
alert.transitioningDelegate = alert
144+
145+
return alert
144146
}
145147

146148

@@ -172,7 +174,7 @@ public class CFAlertViewController: UIViewController {
172174
view.addGestureRecognizer(self.tapGesture)
173175
}
174176

175-
override public func viewDidLoad() {
177+
public override func viewDidLoad() {
176178
super.viewDidLoad()
177179

178180
// Load Variables
@@ -182,7 +184,7 @@ public class CFAlertViewController: UIViewController {
182184
loadDisplayContent()
183185
}
184186

185-
override public func viewWillAppear(_ animated: Bool) {
187+
public override func viewWillAppear(_ animated: Bool) {
186188
super.viewWillAppear(animated)
187189

188190
// Update UI
@@ -216,7 +218,7 @@ public class CFAlertViewController: UIViewController {
216218
dismissAlert(withAnimation: animate, isBackgroundTapped: false, completion: completion)
217219
}
218220

219-
private func dismissAlert(withAnimation animate: Bool, isBackgroundTapped: Bool, completion: ((_: Void) -> Void)?) {
221+
internal func dismissAlert(withAnimation animate: Bool, isBackgroundTapped: Bool, completion: ((_: Void) -> Void)?) {
220222

221223
// Dismiss Self
222224
self.dismiss(animated: animate, completion: {() -> Void in
@@ -305,7 +307,7 @@ public class CFAlertViewController: UIViewController {
305307

306308

307309
// MARK: - Handle Tap Events
308-
@objc private func viewDidTap(_ gestureRecognizer: UITapGestureRecognizer) {
310+
@objc internal func viewDidTap(_ gestureRecognizer: UITapGestureRecognizer) {
309311

310312
// Get Tap Location
311313
let tapLocation: CGPoint = gestureRecognizer.location(in: self.view)
@@ -332,7 +334,7 @@ public class CFAlertViewController: UIViewController {
332334

333335

334336
// MARK: - UIKeyboardWillShowNotification
335-
@objc private func keyboardWillShow(_ notification: Notification) {
337+
@objc internal func keyboardWillShow(_ notification: Notification) {
336338

337339
let info: [AnyHashable: Any]? = notification.userInfo
338340
if let info = info {
@@ -353,7 +355,7 @@ public class CFAlertViewController: UIViewController {
353355
}
354356

355357
// MARK: UIKeyboardWillHideNotification
356-
@objc private func keyboardWillHide(_ notification: Notification) {
358+
@objc internal func keyboardWillHide(_ notification: Notification) {
357359

358360
UIView.animate(withDuration: 0.4, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.0, options: [.beginFromCurrentState, .curveEaseOut, .allowUserInteraction], animations: {() -> Void in
359361
// Update Keyboard Height
@@ -363,7 +365,7 @@ public class CFAlertViewController: UIViewController {
363365
}
364366

365367
// MARK: UITextViewTextDidBeginEditingNotification | UITextFieldTextDidBeginEditingNotification
366-
@objc private func textViewOrTextFieldDidBeginEditing(_ notification: Notification) {
368+
@objc internal func textViewOrTextFieldDidBeginEditing(_ notification: Notification) {
367369

368370
if let notificationObject = notification.object, (notificationObject is UITextField || notificationObject is UITextView) {
369371

@@ -385,7 +387,7 @@ public class CFAlertViewController: UIViewController {
385387

386388

387389
// MARK: - View Rotation / Size Change Method
388-
override public func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
390+
public override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
389391
super.viewWillTransition(to: size, with: coordinator)
390392
// Code here will execute before the rotation begins.
391393
// Equivalent to placing it in the deprecated method -[willRotateToInterfaceOrientation:duration:]
@@ -402,7 +404,7 @@ public class CFAlertViewController: UIViewController {
402404

403405

404406
// MARK: - Key Value Observers
405-
override public func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
407+
public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
406408
if (keyPath == "contentSize") {
407409
// Update Container View Frame Without Animation
408410
updateContainerViewFrame(withAnimation: false)

CFAlertViewController/Cells/CFAlertActionTableViewCell.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,30 +164,31 @@ public class CFAlertActionTableViewCell: UITableViewCell {
164164

165165

166166
// MARK: - Initialization Methods
167-
override public func awakeFromNib() {
167+
public override func awakeFromNib() {
168168
super.awakeFromNib()
169169
basicInitialisation()
170170
}
171171

172-
override public init(style: UITableViewCellStyle, reuseIdentifier: String?) {
172+
public override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
173173
super.init(style: style, reuseIdentifier: reuseIdentifier)
174174
// Initialization code
175175
basicInitialisation()
176176
}
177177

178-
required public init?(coder aDecoder: NSCoder) {
178+
public required init?(coder aDecoder: NSCoder) {
179179
super.init(coder: aDecoder)
180180
}
181181

182-
private func basicInitialisation() {
182+
internal func basicInitialisation() {
183183
// Set Action Button Properties
184184
actionButton?.layer.cornerRadius = 6.0
185185
actionButton?.pushTransformScaleFactor = 0.9
186186
}
187187

188188

189189
// MARK: - Layout Methods
190-
override public func layoutSubviews() {
190+
public override func layoutSubviews() {
191+
super.layoutIfNeeded()
191192
contentView.setNeedsLayout()
192193
contentView.layoutIfNeeded()
193194
}

CFAlertViewController/Cells/CFAlertTitleSubtitleTableViewCell.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,22 @@ public class CFAlertTitleSubtitleTableViewCell: UITableViewCell {
5858

5959

6060
// MARK: Initialization Methods
61-
override public func awakeFromNib() {
61+
public override func awakeFromNib() {
6262
super.awakeFromNib()
6363
basicInitialisation()
6464
}
6565

66-
override public init(style: UITableViewCellStyle, reuseIdentifier: String?) {
66+
public override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
6767
super.init(style: style, reuseIdentifier: reuseIdentifier)
6868
// Initialization code
6969
basicInitialisation()
7070
}
7171

72-
required public init?(coder aDecoder: NSCoder) {
72+
public required init?(coder aDecoder: NSCoder) {
7373
super.init(coder: aDecoder)
7474
}
7575

76-
private func basicInitialisation() {
76+
internal func basicInitialisation() {
7777
// Reset Text
7878
setTitle(nil, subtitle: nil, alignment: .center)
7979
// Set Content Leading Space

CFAlertViewController/Models/CFAlertAction.swift

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,30 @@ public class CFAlertAction: NSObject, NSCopying {
3838

3939

4040
// MARK: - Initialisation Method
41-
convenience public init(title: String?, style: CFAlertActionStyle, alignment: CFAlertActionAlignment, backgroundColor: UIColor?, textColor: UIColor?, handler: CFAlertActionHandlerBlock?) {
42-
self.init()
41+
public class func action(title: String?, style: CFAlertActionStyle, alignment: CFAlertActionAlignment, backgroundColor: UIColor?, textColor: UIColor?, handler: CFAlertActionHandlerBlock?) -> CFAlertAction {
4342

44-
// Set Properties
45-
self.title = title
46-
self.style = style
47-
self.alignment = alignment
48-
self.backgroundColor = backgroundColor
49-
self.textColor = textColor
50-
self.handler = handler
43+
let action = CFAlertAction.init()
44+
45+
// Set Alert Properties
46+
action.title = title
47+
action.style = style
48+
action.alignment = alignment
49+
action.backgroundColor = backgroundColor
50+
action.textColor = textColor
51+
action.handler = handler
52+
53+
return action
5154
}
5255

5356

5457
// MARK: - NSCopying
5558
public func copy(with zone: NSZone? = nil) -> Any {
56-
57-
let copy : CFAlertAction = CFAlertAction(title: title,
58-
style: style,
59-
alignment: alignment,
60-
backgroundColor: backgroundColor,
61-
textColor: textColor,
62-
handler: handler)
59+
let copy = CFAlertAction.action(title: title,
60+
style: style,
61+
alignment: alignment,
62+
backgroundColor: backgroundColor,
63+
textColor: textColor,
64+
handler: handler)
6365
return copy
6466
}
6567
}

CFAlertViewController/Subclass/CFPushButton/CFPushButton.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ open class CFPushButton: UIButton {
5858
open var extraParam: Any?
5959

6060
private var normalStateBackgroundColor: UIColor?
61-
override open var backgroundColor: UIColor? {
61+
open override var backgroundColor: UIColor? {
6262
didSet {
6363
// Store Normal State Background Color
6464
normalStateBackgroundColor = backgroundColor
@@ -67,12 +67,12 @@ open class CFPushButton: UIButton {
6767

6868

6969
// MARK: - Initialization Methods
70-
required public init?(coder: NSCoder) {
70+
public required init?(coder: NSCoder) {
7171
super.init(coder: coder)
7272
basicInitialisation()
7373
}
7474

75-
override public init(frame: CGRect) {
75+
public override init(frame: CGRect) {
7676
super.init(frame: frame)
7777
basicInitialisation()
7878
}
@@ -85,17 +85,17 @@ open class CFPushButton: UIButton {
8585

8686

8787
// MARK: - Touch Events
88-
override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
88+
open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
8989
super.touchesBegan(touches, with: event)
9090
pushButton(pushButton: true, shouldAnimate: true, completion: nil)
9191
}
9292

93-
override open func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
93+
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
9494
super.touchesEnded(touches, with: event)
9595
pushButton(pushButton: false, shouldAnimate: true, completion: nil)
9696
}
9797

98-
override open func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
98+
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
9999
super.touchesCancelled(touches, with: event)
100100
pushButton(pushButton: false, shouldAnimate: true, completion: nil)
101101
}

CFAlertViewController/Transitions/CFAlertViewControllerActionSheetTransition.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class CFAlertViewControllerActionSheetTransition: NSObject {
2525

2626

2727
// MARK: - Initialisation Methods
28-
override public init() {
28+
public override init() {
2929
super.init()
3030

3131
// Default Transition Type

CFAlertViewController/Transitions/CFAlertViewControllerPopupTransition.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class CFAlertViewControllerPopupTransition: NSObject {
2525

2626

2727
// MARK: - Initialisation Methods
28-
override public init() {
28+
public override init() {
2929
super.init()
3030

3131
// Default Transition Type

Demo/CFAlertViewControllerDemo/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>2.0.2</string>
18+
<string>2.0.3</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

0 commit comments

Comments
 (0)