From 47fbdcdf84a667bc70baae629fe8ea17354852fe Mon Sep 17 00:00:00 2001 From: Christian Cabarrocas Date: Sat, 26 Mar 2016 11:18:38 +0100 Subject: [PATCH 1/2] Added new test on SCLButton - Removed commented code --- SCLAlertViewTests/SCLButtonTests.swift | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/SCLAlertViewTests/SCLButtonTests.swift b/SCLAlertViewTests/SCLButtonTests.swift index 9d42f3c..8c9c102 100644 --- a/SCLAlertViewTests/SCLButtonTests.swift +++ b/SCLAlertViewTests/SCLButtonTests.swift @@ -54,7 +54,7 @@ class SCLButtonTests: XCTestCase { func testButtonTargets() { let alert = SCLAlertView() - alert.addButton("testButtontitle") {} + alert.addButton("testButtonTitle") {} let buttonTargets = alert.buttons[0].allTargets().first let button = alert.buttons[0] @@ -78,6 +78,18 @@ class SCLButtonTests: XCTestCase { XCTAssertTrue(buttonActionsTouchUpOutside![0] == "buttonRelease:") } + func testButtonSelectorAndTarget() { + let alert = SCLAlertView() + let testTarget = SCLAlertView() + let testSelector = Selector() + alert.addButton("testButtonTitle", target: testTarget, selector: testSelector) + let button = alert.buttons[0] + XCTAssertTrue(button.target.isKindOfClass(SCLAlertView.self)) + XCTAssertTrue(button.selector == testSelector) + XCTAssertTrue(button.actionType == SCLActionType.Selector) + + } + func testButtonActionType() { let alert = SCLAlertView() alert.addButton("testButtonTitle") {} @@ -85,14 +97,3 @@ class SCLButtonTests: XCTestCase { XCTAssertTrue(button.actionType == SCLActionType.Closure) } } - - -//public func addButton(title:String, action:()->Void)->SCLButton { -// let btn = addButton(title) -// btn.actionType = SCLActionType.Closure -// btn.action = action -// btn.addTarget(self, action:Selector("buttonTapped:"), forControlEvents:.TouchUpInside) -// btn.addTarget(self, action:Selector("buttonTapDown:"), forControlEvents:[.TouchDown, .TouchDragEnter]) -// btn.addTarget(self, action:Selector("buttonRelease:"), forControlEvents:[.TouchUpInside, .TouchUpOutside, .TouchCancel, .TouchDragOutside] ) -// return btn -//} \ No newline at end of file From 7ef01289a2e77d84fcc4cf27686b5702108dab75 Mon Sep 17 00:00:00 2001 From: Christian Cabarrocas Date: Sat, 26 Mar 2016 12:27:41 +0100 Subject: [PATCH 2/2] Method refactor -keyboardWillShow refactor to avoid nested if let --- SCLAlertView/SCLAlertView.swift | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/SCLAlertView/SCLAlertView.swift b/SCLAlertView/SCLAlertView.swift index e8cc763..f23e13b 100644 --- a/SCLAlertView/SCLAlertView.swift +++ b/SCLAlertView/SCLAlertView.swift @@ -358,18 +358,17 @@ public class SCLAlertView: UIViewController { func keyboardWillShow(notification: NSNotification) { keyboardHasBeenShown = true - if let userInfo = notification.userInfo { - if let beginKeyBoardFrame = userInfo[UIKeyboardFrameBeginUserInfoKey]?.CGRectValue.origin.y { - if let endKeyBoardFrame = userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue.origin.y { - tmpContentViewFrameOrigin = self.contentView.frame.origin - tmpCircleViewFrameOrigin = self.circleBG.frame.origin - let newContentViewFrameY = beginKeyBoardFrame - endKeyBoardFrame - self.contentView.frame.origin.y - let newBallViewFrameY = self.circleBG.frame.origin.y - newContentViewFrameY - self.contentView.frame.origin.y -= newContentViewFrameY - self.circleBG.frame.origin.y = newBallViewFrameY - } - } - } + + guard let userInfo = notification.userInfo else {return} + guard let beginKeyBoardFrame = userInfo[UIKeyboardFrameBeginUserInfoKey]?.CGRectValue.origin.y else {return} + guard let endKeyBoardFrame = userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue.origin.y else {return} + + tmpContentViewFrameOrigin = self.contentView.frame.origin + tmpCircleViewFrameOrigin = self.circleBG.frame.origin + let newContentViewFrameY = beginKeyBoardFrame - endKeyBoardFrame - self.contentView.frame.origin.y + let newBallViewFrameY = self.circleBG.frame.origin.y - newContentViewFrameY + self.contentView.frame.origin.y -= newContentViewFrameY + self.circleBG.frame.origin.y = newBallViewFrameY } func keyboardWillHide(notification: NSNotification) {