diff --git a/SweetAlert.xcodeproj/project.pbxproj b/SweetAlert.xcodeproj/project.pbxproj index b938371..1315d9a 100644 --- a/SweetAlert.xcodeproj/project.pbxproj +++ b/SweetAlert.xcodeproj/project.pbxproj @@ -134,11 +134,12 @@ 9B4CD1001A06E55200B65DE0 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "Sahil Wasan"; TargetAttributes = { 9B4CD1071A06E55200B65DE0 = { CreatedOnToolsVersion = 6.1; + LastSwiftMigration = 0800; }; }; }; @@ -223,8 +224,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -233,6 +236,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -266,8 +270,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -275,6 +281,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -284,6 +291,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.1; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; VALIDATE_PRODUCT = YES; }; name = Release; @@ -296,6 +304,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "GNDBL.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -307,6 +316,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "GNDBL.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/SweetAlert/AppDelegate.swift b/SweetAlert/AppDelegate.swift index 630ddef..b005a4f 100644 --- a/SweetAlert/AppDelegate.swift +++ b/SweetAlert/AppDelegate.swift @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } diff --git a/SweetAlert/SweetAlert.swift b/SweetAlert/SweetAlert.swift index 52c18c8..e501fc5 100644 --- a/SweetAlert/SweetAlert.swift +++ b/SweetAlert/SweetAlert.swift @@ -11,11 +11,11 @@ import UIKit import QuartzCore public enum AlertStyle { - case Success,Error,Warning,None - case CustomImag(imageFile:String) + case success,error,warning,none + case customImag(imageFile:String) } -public class SweetAlert: UIViewController { +open class SweetAlert: UIViewController { let kBakcgroundTansperancy: CGFloat = 0.7 let kHeightMargin: CGFloat = 10.0 let KTopMargin: CGFloat = 20.0 @@ -33,13 +33,13 @@ public class SweetAlert: UIViewController { var animatedView: AnimatableView? var imageView:UIImageView? var subTitleTextView = UITextView() - var userAction:((isOtherButton: Bool) -> Void)? = nil + var userAction:((_ isOtherButton: Bool) -> Void)? = nil let kFont = "Helvetica" init() { super.init(nibName: nil, bundle: nil) - self.view.frame = UIScreen.mainScreen().bounds - self.view.autoresizingMask = [UIViewAutoresizing.FlexibleHeight, UIViewAutoresizing.FlexibleWidth] + self.view.frame = UIScreen.main.bounds + self.view.autoresizingMask = [UIViewAutoresizing.flexibleHeight, UIViewAutoresizing.flexibleWidth] self.view.backgroundColor = UIColor(red:0, green:0, blue:0, alpha:kBakcgroundTansperancy) self.view.addSubview(contentView) @@ -51,7 +51,7 @@ public class SweetAlert: UIViewController { fatalError("init(coder:) has not been implemented") } - private func setupContentView() { + fileprivate func setupContentView() { contentView.backgroundColor = UIColor(white: 1.0, alpha: 1.0) contentView.layer.cornerRadius = 5.0 contentView.layer.masksToBounds = true @@ -59,28 +59,28 @@ public class SweetAlert: UIViewController { contentView.addSubview(titleLabel) contentView.addSubview(subTitleTextView) contentView.backgroundColor = UIColor.colorFromRGB(0xFFFFFF) - contentView.layer.borderColor = UIColor.colorFromRGB(0xCCCCCC).CGColor + contentView.layer.borderColor = UIColor.colorFromRGB(0xCCCCCC).cgColor view.addSubview(contentView) } - private func setupTitleLabel() { + fileprivate func setupTitleLabel() { titleLabel.text = "" titleLabel.numberOfLines = 1 - titleLabel.textAlignment = .Center + titleLabel.textAlignment = .center titleLabel.font = UIFont(name: kFont, size:25) titleLabel.textColor = UIColor.colorFromRGB(0x575757) } - private func setupSubtitleTextView() { + fileprivate func setupSubtitleTextView() { subTitleTextView.text = "" - subTitleTextView.textAlignment = .Center + subTitleTextView.textAlignment = .center subTitleTextView.font = UIFont(name: kFont, size:16) subTitleTextView.textColor = UIColor.colorFromRGB(0x797979) - subTitleTextView.editable = false + subTitleTextView.isEditable = false } - private func resizeAndRelayout() { - let mainScreenBounds = UIScreen.mainScreen().bounds + fileprivate func resizeAndRelayout() { + let mainScreenBounds = UIScreen.main.bounds self.view.frame.size = mainScreenBounds.size let x: CGFloat = kWidthMargin var y: CGFloat = KTopMargin @@ -108,7 +108,7 @@ public class SweetAlert: UIViewController { // Subtitle if self.subTitleTextView.text.isEmpty == false { let subtitleString = subTitleTextView.text! as NSString - let rect = subtitleString.boundingRectWithSize(CGSize(width: width, height: 0.0), options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: [NSFontAttributeName:subTitleTextView.font!], context: nil) + let rect = subtitleString.boundingRect(with: CGSize(width: width, height: 0.0), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes: [NSFontAttributeName:subTitleTextView.font!], context: nil) textViewHeight = ceil(rect.size.height) + 10.0 subTitleTextView.frame = CGRect(x: x, y: y, width: width, height: textViewHeight) contentView.addSubview(subTitleTextView) @@ -117,8 +117,8 @@ public class SweetAlert: UIViewController { var buttonRect:[CGRect] = [] for button in buttons { - let string = button.titleForState(UIControlState.Normal)! as NSString - buttonRect.append(string.boundingRectWithSize(CGSize(width: width, height:0.0), options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes:[NSFontAttributeName:button.titleLabel!.font], context:nil)) + let string = button.title(for: UIControlState())! as NSString + buttonRect.append(string.boundingRect(with: CGSize(width: width, height:0.0), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes:[NSFontAttributeName:button.titleLabel!.font], context:nil)) } var totalWidth: CGFloat = 0.0 @@ -130,13 +130,13 @@ public class SweetAlert: UIViewController { } y += kHeightMargin var buttonX = (kContentWidth - totalWidth ) / 2.0 - for var i = 0; i < buttons.count; i++ { + for i in 0 ..< buttons.count { buttons[i].frame = CGRect(x: buttonX, y: y, width: buttonRect[i].size.width + 20.0, height: buttonRect[i].size.height + 10.0) buttonX = buttons[i].frame.origin.x + kWidthMargin + buttonRect[i].size.width + 20.0 buttons[i].layer.cornerRadius = 5.0 self.contentView.addSubview(buttons[i]) - buttons[i].addTarget(self, action: "pressed:", forControlEvents: UIControlEvents.TouchUpInside) + buttons[i].addTarget(self, action: #selector(SweetAlert.pressed(_:)), for: UIControlEvents.touchUpInside) } y += kHeightMargin + buttonRect[0].size.height + 10.0 @@ -157,18 +157,18 @@ public class SweetAlert: UIViewController { contentView.clipsToBounds = true } - public func pressed(sender: UIButton!) { + open func pressed(_ sender: UIButton!) { self.closeAlert(sender.tag) } - public override func viewWillLayoutSubviews() { + open override func viewWillLayoutSubviews() { super.viewWillLayoutSubviews() - var sz = UIScreen.mainScreen().bounds.size - let sver = UIDevice.currentDevice().systemVersion as NSString + var sz = UIScreen.main.bounds.size + let sver = UIDevice.current.systemVersion as NSString let ver = sver.floatValue if ver < 8.0 { // iOS versions before 7.0 did not switch the width and height on device roration - if UIInterfaceOrientationIsLandscape(UIApplication.sharedApplication().statusBarOrientation) { + if UIInterfaceOrientationIsLandscape(UIApplication.shared.statusBarOrientation) { let ssz = sz sz = CGSize(width:ssz.height, height:ssz.width) } @@ -176,15 +176,15 @@ public class SweetAlert: UIViewController { self.resizeAndRelayout() } - func closeAlert(buttonIndex:Int){ + func closeAlert(_ buttonIndex:Int){ if userAction != nil { let isOtherButton = buttonIndex == 0 ? true: false SweetAlertContext.shouldNotAnimate = true - userAction!(isOtherButton: isOtherButton) + userAction!(isOtherButton) SweetAlertContext.shouldNotAnimate = false } - UIView.animateWithDuration(0.5, delay: 0.0, options: UIViewAnimationOptions.CurveEaseOut, animations: { () -> Void in + UIView.animate(withDuration: 0.5, delay: 0.0, options: UIViewAnimationOptions.curveEaseOut, animations: { () -> Void in self.view.alpha = 0.0 }) { (Bool) -> Void in self.view.removeFromSuperview() @@ -205,64 +205,64 @@ public class SweetAlert: UIViewController { self.contentView = UIView() } - public func showAlert(title: String) -> SweetAlert { - self.showAlert(title, subTitle: nil, style: .None) + open func showAlert(_ title: String) -> SweetAlert { + _ = showAlert(title, subTitle: nil, style: .none) return self } - public func showAlert(title: String, subTitle: String?, style: AlertStyle) -> SweetAlert { - self.showAlert(title, subTitle: subTitle, style: style, buttonTitle: "OK") + open func showAlert(_ title: String, subTitle: String?, style: AlertStyle) -> SweetAlert { + _ = showAlert(title, subTitle: subTitle, style: style, buttonTitle: "OK") return self } - public func showAlert(title: String, subTitle: String?, style: AlertStyle,buttonTitle: String, action: ((isOtherButton: Bool) -> Void)? = nil) -> SweetAlert { - self.showAlert(title, subTitle: subTitle, style: style, buttonTitle: buttonTitle,buttonColor: UIColor.colorFromRGB(0xAEDEF4)) + open func showAlert(_ title: String, subTitle: String?, style: AlertStyle,buttonTitle: String, action: ((_ isOtherButton: Bool) -> Void)? = nil) -> SweetAlert { + _ = showAlert(title, subTitle: subTitle, style: style, buttonTitle: buttonTitle,buttonColor: UIColor.colorFromRGB(0xAEDEF4)) userAction = action return self } - public func showAlert(title: String, subTitle: String?, style: AlertStyle,buttonTitle: String,buttonColor: UIColor,action: ((isOtherButton: Bool) -> Void)? = nil) -> SweetAlert { - self.showAlert(title, subTitle: subTitle, style: style, buttonTitle: buttonTitle,buttonColor: buttonColor,otherButtonTitle: + open func showAlert(_ title: String, subTitle: String?, style: AlertStyle,buttonTitle: String,buttonColor: UIColor,action: ((_ isOtherButton: Bool) -> Void)? = nil) -> SweetAlert { + _ = showAlert(title, subTitle: subTitle, style: style, buttonTitle: buttonTitle,buttonColor: buttonColor,otherButtonTitle: nil) userAction = action return self } - public func showAlert(title: String, subTitle: String?, style: AlertStyle,buttonTitle: String,buttonColor: UIColor,otherButtonTitle: - String?, action: ((isOtherButton: Bool) -> Void)? = nil) -> SweetAlert { + open func showAlert(_ title: String, subTitle: String?, style: AlertStyle,buttonTitle: String,buttonColor: UIColor,otherButtonTitle: + String?, action: ((_ isOtherButton: Bool) -> Void)? = nil) -> SweetAlert { self.showAlert(title, subTitle: subTitle, style: style, buttonTitle: buttonTitle,buttonColor: buttonColor,otherButtonTitle: - otherButtonTitle,otherButtonColor: UIColor.redColor()) + otherButtonTitle,otherButtonColor: UIColor.red) userAction = action return self } - public func showAlert(title: String, subTitle: String?, style: AlertStyle,buttonTitle: String,buttonColor: UIColor,otherButtonTitle: - String?, otherButtonColor: UIColor?,action: ((isOtherButton: Bool) -> Void)? = nil) { + open func showAlert(_ title: String, subTitle: String?, style: AlertStyle,buttonTitle: String,buttonColor: UIColor,otherButtonTitle: + String?, otherButtonColor: UIColor?,action: ((_ isOtherButton: Bool) -> Void)? = nil) { userAction = action - let window: UIWindow = UIApplication.sharedApplication().keyWindow! + let window: UIWindow = UIApplication.shared.keyWindow! window.addSubview(view) - window.bringSubviewToFront(view) + window.bringSubview(toFront: view) view.frame = window.bounds self.setupContentView() self.setupTitleLabel() self.setupSubtitleTextView() switch style { - case .Success: + case .success: self.animatedView = SuccessAnimatedView() - case .Error: + case .error: self.animatedView = CancelAnimatedView() - case .Warning: + case .warning: self.animatedView = InfoAnimatedView() - case let .CustomImag(imageFile): + case let .customImag(imageFile): if let image = UIImage(named: imageFile) { self.imageView = UIImageView(image: image) } - case .None: + case .none: self.animatedView = nil } @@ -272,19 +272,19 @@ public class SweetAlert: UIViewController { } buttons = [] if buttonTitle.isEmpty == false { - let button: UIButton = UIButton(type: UIButtonType.Custom) - button.setTitle(buttonTitle, forState: UIControlState.Normal) + let button: UIButton = UIButton(type: UIButtonType.custom) + button.setTitle(buttonTitle, for: UIControlState()) button.backgroundColor = buttonColor - button.userInteractionEnabled = true + button.isUserInteractionEnabled = true button.tag = 0 buttons.append(button) } if otherButtonTitle != nil && otherButtonTitle!.isEmpty == false { - let button: UIButton = UIButton(type: UIButtonType.Custom) - button.setTitle(otherButtonTitle, forState: UIControlState.Normal) + let button: UIButton = UIButton(type: UIButtonType.custom) + button.setTitle(otherButtonTitle, for: UIControlState()) button.backgroundColor = otherButtonColor - button.addTarget(self, action: "pressed:", forControlEvents: UIControlEvents.TouchUpInside) + button.addTarget(self, action: #selector(SweetAlert.pressed(_:)), for: UIControlEvents.touchUpInside) button.tag = 1 buttons.append(button) } @@ -304,33 +304,33 @@ public class SweetAlert: UIViewController { func animateAlert() { view.alpha = 0; - UIView.animateWithDuration(0.1, animations: { () -> Void in + UIView.animate(withDuration: 0.1, animations: { () -> Void in self.view.alpha = 1.0; }) let previousTransform = self.contentView.transform self.contentView.layer.transform = CATransform3DMakeScale(0.9, 0.9, 0.0); - UIView.animateWithDuration(0.2, animations: { () -> Void in + UIView.animate(withDuration: 0.2, animations: { () -> Void in self.contentView.layer.transform = CATransform3DMakeScale(1.1, 1.1, 0.0); - }) { (Bool) -> Void in - UIView.animateWithDuration(0.1, animations: { () -> Void in + }, completion: { (Bool) -> Void in + UIView.animate(withDuration: 0.1, animations: { () -> Void in self.contentView.layer.transform = CATransform3DMakeScale(0.9, 0.9, 0.0); - }) { (Bool) -> Void in - UIView.animateWithDuration(0.1, animations: { () -> Void in + }, completion: { (Bool) -> Void in + UIView.animate(withDuration: 0.1, animations: { () -> Void in self.contentView.layer.transform = CATransform3DMakeScale(1.0, 1.0, 0.0); if self.animatedView != nil { self.animatedView!.animate() } - }) { (Bool) -> Void in + }, completion: { (Bool) -> Void in self.contentView.transform = previousTransform - } - } - } + }) + }) + }) } - private struct SweetAlertContext { + fileprivate struct SweetAlertContext { static var shouldNotAnimate = false } } @@ -368,30 +368,30 @@ class CancelAnimatedView: AnimatableView { fatalError("init(coder:) has not been implemented") } - private var outlineCircle: CGPath { + fileprivate var outlineCircle: CGPath { let path = UIBezierPath() let startAngle: CGFloat = CGFloat((0) / 180.0 * M_PI) //0 let endAngle: CGFloat = CGFloat((360) / 180.0 * M_PI) //360 - path.addArcWithCenter(CGPointMake(self.frame.size.width/2.0, self.frame.size.width/2.0), radius: self.frame.size.width/2.0, startAngle: startAngle, endAngle: endAngle, clockwise: false) + path.addArc(withCenter: CGPoint(x: self.frame.size.width/2.0, y: self.frame.size.width/2.0), radius: self.frame.size.width/2.0, startAngle: startAngle, endAngle: endAngle, clockwise: false) - return path.CGPath + return path.cgPath } - private var crossPath: CGPath { + fileprivate var crossPath: CGPath { let path = UIBezierPath() let factor:CGFloat = self.frame.size.width / 5.0 - path.moveToPoint(CGPoint(x: self.frame.size.height/2.0-factor,y: self.frame.size.height/2.0-factor)) - path.addLineToPoint(CGPoint(x: self.frame.size.height/2.0+factor,y: self.frame.size.height/2.0+factor)) - path.moveToPoint(CGPoint(x: self.frame.size.height/2.0+factor,y: self.frame.size.height/2.0-factor)) - path.addLineToPoint(CGPoint(x: self.frame.size.height/2.0-factor,y: self.frame.size.height/2.0+factor)) + path.move(to: CGPoint(x: self.frame.size.height/2.0-factor,y: self.frame.size.height/2.0-factor)) + path.addLine(to: CGPoint(x: self.frame.size.height/2.0+factor,y: self.frame.size.height/2.0+factor)) + path.move(to: CGPoint(x: self.frame.size.height/2.0+factor,y: self.frame.size.height/2.0-factor)) + path.addLine(to: CGPoint(x: self.frame.size.height/2.0-factor,y: self.frame.size.height/2.0+factor)) - return path.CGPath + return path.cgPath } - private func setupLayers() { + fileprivate func setupLayers() { circleLayer.path = outlineCircle - circleLayer.fillColor = UIColor.clearColor().CGColor; - circleLayer.strokeColor = UIColor.colorFromRGB(0xF27474).CGColor; + circleLayer.fillColor = UIColor.clear.cgColor; + circleLayer.strokeColor = UIColor.colorFromRGB(0xF27474).cgColor; circleLayer.lineCap = kCALineCapRound circleLayer.lineWidth = 4; circleLayer.frame = CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height) @@ -399,8 +399,8 @@ class CancelAnimatedView: AnimatableView { self.layer.addSublayer(circleLayer) crossPathLayer.path = crossPath - crossPathLayer.fillColor = UIColor.clearColor().CGColor; - crossPathLayer.strokeColor = UIColor.colorFromRGB(0xF27474).CGColor; + crossPathLayer.fillColor = UIColor.clear.cgColor; + crossPathLayer.strokeColor = UIColor.colorFromRGB(0xF27474).cgColor; crossPathLayer.lineCap = kCALineCapRound crossPathLayer.lineWidth = 4; crossPathLayer.frame = CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height) @@ -421,11 +421,11 @@ class CancelAnimatedView: AnimatableView { let animation = CABasicAnimation(keyPath: "transform") let time = 0.3 animation.duration = time; - animation.fromValue = NSValue(CATransform3D: t) - animation.toValue = NSValue(CATransform3D:t2) - animation.removedOnCompletion = false + animation.fromValue = NSValue(caTransform3D: t) + animation.toValue = NSValue(caTransform3D:t2) + animation.isRemovedOnCompletion = false animation.fillMode = kCAFillModeForwards - self.circleLayer.addAnimation(animation, forKey: "transform") + self.circleLayer.add(animation, forKey: "transform") var scale = CATransform3DIdentity; @@ -435,19 +435,19 @@ class CancelAnimatedView: AnimatableView { let crossAnimation = CABasicAnimation(keyPath: "transform") crossAnimation.duration = 0.3; crossAnimation.beginTime = CACurrentMediaTime() + time - crossAnimation.fromValue = NSValue(CATransform3D: scale) + crossAnimation.fromValue = NSValue(caTransform3D: scale) crossAnimation.timingFunction = CAMediaTimingFunction(controlPoints: 0.25, 0.8, 0.7, 2.0) - crossAnimation.toValue = NSValue(CATransform3D:CATransform3DIdentity) - self.crossPathLayer.addAnimation(crossAnimation, forKey: "scale") + crossAnimation.toValue = NSValue(caTransform3D:CATransform3DIdentity) + self.crossPathLayer.add(crossAnimation, forKey: "scale") let fadeInAnimation = CABasicAnimation(keyPath: "opacity") fadeInAnimation.duration = 0.3; fadeInAnimation.beginTime = CACurrentMediaTime() + time fadeInAnimation.fromValue = 0.3 fadeInAnimation.toValue = 1.0 - fadeInAnimation.removedOnCompletion = false + fadeInAnimation.isRemovedOnCompletion = false fadeInAnimation.fillMode = kCAFillModeForwards - self.crossPathLayer.addAnimation(fadeInAnimation, forKey: "opacity") + self.crossPathLayer.add(fadeInAnimation, forKey: "opacity") } } @@ -474,21 +474,21 @@ class InfoAnimatedView: AnimatableView { let path = UIBezierPath() let startAngle: CGFloat = CGFloat((0) / 180.0 * M_PI) //0 let endAngle: CGFloat = CGFloat((360) / 180.0 * M_PI) //360 - path.addArcWithCenter(CGPointMake(self.frame.size.width/2.0, self.frame.size.width/2.0), radius: self.frame.size.width/2.0, startAngle: startAngle, endAngle: endAngle, clockwise: false) + path.addArc(withCenter: CGPoint(x: self.frame.size.width/2.0, y: self.frame.size.width/2.0), radius: self.frame.size.width/2.0, startAngle: startAngle, endAngle: endAngle, clockwise: false) let factor:CGFloat = self.frame.size.width / 1.5 - path.moveToPoint(CGPoint(x: self.frame.size.width/2.0 , y: 15.0)) - path.addLineToPoint(CGPoint(x: self.frame.size.width/2.0,y: factor)) - path.moveToPoint(CGPoint(x: self.frame.size.width/2.0,y: factor + 10.0)) - path.addArcWithCenter(CGPoint(x: self.frame.size.width/2.0,y: factor + 10.0), radius: 1.0, startAngle: startAngle, endAngle: endAngle, clockwise: true) + path.move(to: CGPoint(x: self.frame.size.width/2.0 , y: 15.0)) + path.addLine(to: CGPoint(x: self.frame.size.width/2.0,y: factor)) + path.move(to: CGPoint(x: self.frame.size.width/2.0,y: factor + 10.0)) + path.addArc(withCenter: CGPoint(x: self.frame.size.width/2.0,y: factor + 10.0), radius: 1.0, startAngle: startAngle, endAngle: endAngle, clockwise: true) - return path.CGPath + return path.cgPath } func setupLayers() { circleLayer.path = outlineCircle - circleLayer.fillColor = UIColor.clearColor().CGColor; - circleLayer.strokeColor = UIColor.colorFromRGB(0xF8D486).CGColor; + circleLayer.fillColor = UIColor.clear.cgColor; + circleLayer.strokeColor = UIColor.colorFromRGB(0xF8D486).cgColor; circleLayer.lineCap = kCALineCapRound circleLayer.lineWidth = 4; circleLayer.frame = CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height) @@ -503,9 +503,9 @@ class InfoAnimatedView: AnimatableView { colorAnimation.repeatCount = HUGE colorAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) colorAnimation.autoreverses = true - colorAnimation.fromValue = UIColor.colorFromRGB(0xF7D58B).CGColor - colorAnimation.toValue = UIColor.colorFromRGB(0xF2A665).CGColor - circleLayer.addAnimation(colorAnimation, forKey: "strokeColor") + colorAnimation.fromValue = UIColor.colorFromRGB(0xF7D58B).cgColor + colorAnimation.toValue = UIColor.colorFromRGB(0xF2A665).cgColor + circleLayer.add(colorAnimation, forKey: "strokeColor") } } @@ -535,38 +535,38 @@ class SuccessAnimatedView: AnimatableView { let path = UIBezierPath() let startAngle: CGFloat = CGFloat((0) / 180.0 * M_PI) //0 let endAngle: CGFloat = CGFloat((360) / 180.0 * M_PI) //360 - path.addArcWithCenter(CGPointMake(self.frame.size.width/2.0, self.frame.size.height/2.0), radius: self.frame.size.width/2.0, startAngle: startAngle, endAngle: endAngle, clockwise: false) - return path.CGPath + path.addArc(withCenter: CGPoint(x: self.frame.size.width/2.0, y: self.frame.size.height/2.0), radius: self.frame.size.width/2.0, startAngle: startAngle, endAngle: endAngle, clockwise: false) + return path.cgPath } var path: CGPath { let path = UIBezierPath() let startAngle:CGFloat = CGFloat((60) / 180.0 * M_PI) //60 let endAngle:CGFloat = CGFloat((200) / 180.0 * M_PI) //190 - path.addArcWithCenter(CGPointMake(self.frame.size.width/2.0, self.frame.size.height/2.0), radius: self.frame.size.width/2.0, startAngle: startAngle, endAngle: endAngle, clockwise: false) - path.addLineToPoint(CGPoint(x: 36.0 - 10.0 ,y: 60.0 - 10.0)) - path.addLineToPoint(CGPoint(x: 85.0 - 20.0, y: 30.0 - 20.0)) - return path.CGPath + path.addArc(withCenter: CGPoint(x: self.frame.size.width/2.0, y: self.frame.size.height/2.0), radius: self.frame.size.width/2.0, startAngle: startAngle, endAngle: endAngle, clockwise: false) + path.addLine(to: CGPoint(x: 36.0 - 10.0 ,y: 60.0 - 10.0)) + path.addLine(to: CGPoint(x: 85.0 - 20.0, y: 30.0 - 20.0)) + return path.cgPath } func setupLayers() { - outlineLayer.position = CGPointMake(0, - 0); + outlineLayer.position = CGPoint(x: 0, + y: 0); outlineLayer.path = outlineCircle - outlineLayer.fillColor = UIColor.clearColor().CGColor; - outlineLayer.strokeColor = UIColor(red: 150.0/255.0, green: 216.0/255.0, blue: 115.0/255.0, alpha: 1.0).CGColor; + outlineLayer.fillColor = UIColor.clear.cgColor; + outlineLayer.strokeColor = UIColor(red: 150.0/255.0, green: 216.0/255.0, blue: 115.0/255.0, alpha: 1.0).cgColor; outlineLayer.lineCap = kCALineCapRound outlineLayer.lineWidth = 4; outlineLayer.opacity = 0.1 self.layer.addSublayer(outlineLayer) - circleLayer.position = CGPointMake(0, - 0); + circleLayer.position = CGPoint(x: 0, + y: 0); circleLayer.path = path - circleLayer.fillColor = UIColor.clearColor().CGColor; - circleLayer.strokeColor = UIColor(red: 150.0/255.0, green: 216.0/255.0, blue: 115.0/255.0, alpha: 1.0).CGColor; + circleLayer.fillColor = UIColor.clear.cgColor; + circleLayer.strokeColor = UIColor(red: 150.0/255.0, green: 216.0/255.0, blue: 115.0/255.0, alpha: 1.0).cgColor; circleLayer.lineCap = kCALineCapRound circleLayer.lineWidth = 4; circleLayer.actions = [ @@ -595,14 +595,14 @@ class SuccessAnimatedView: AnimatableView { strokeStart.timingFunction = timing circleLayer.strokeStart = 0.68 circleLayer.strokeEnd = 0.93 - self.circleLayer.addAnimation(strokeEnd, forKey: "strokeEnd") - self.circleLayer.addAnimation(strokeStart, forKey: "strokeStart") + self.circleLayer.add(strokeEnd, forKey: "strokeEnd") + self.circleLayer.add(strokeStart, forKey: "strokeStart") } } extension UIColor { - class func colorFromRGB(rgbValue: UInt) -> UIColor { + class func colorFromRGB(_ rgbValue: UInt) -> UIColor { return UIColor( red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0, green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0, diff --git a/SweetAlert/ViewController.swift b/SweetAlert/ViewController.swift index 34ac7d4..ab5ada2 100644 --- a/SweetAlert/ViewController.swift +++ b/SweetAlert/ViewController.swift @@ -17,7 +17,7 @@ class ViewController: UIViewController { self.view.backgroundColor = UIColor(red: 242.0/255.0, green: 244.0/255.0, blue: 246.0/255.0, alpha: 1.0) } - override func viewDidAppear(animated: Bool) { + override func viewDidAppear(_ animated: Bool) { } @@ -28,47 +28,47 @@ class ViewController: UIViewController { } - @IBAction func aBasicMessageAlert(sender: AnyObject) { - SweetAlert().showAlert("Here's a message!") + @IBAction func aBasicMessageAlert(_ sender: AnyObject) { + _ = SweetAlert().showAlert("Here's a message!") } - @IBAction func subtitleAlert(sender: AnyObject) { + @IBAction func subtitleAlert(_ sender: AnyObject) { - SweetAlert().showAlert("Here's a message!", subTitle: "It's pretty, isn't it?", style: AlertStyle.None) + _ = SweetAlert().showAlert("Here's a message!", subTitle: "It's pretty, isn't it?", style: AlertStyle.none) } - @IBAction func sucessAlert(sender: AnyObject) { - SweetAlert().showAlert("Good job!", subTitle: "You clicked the button!", style: AlertStyle.Success) + @IBAction func sucessAlert(_ sender: AnyObject) { + _ = SweetAlert().showAlert("Good job!", subTitle: "You clicked the button!", style: AlertStyle.success) } - @IBAction func warningAlert(sender: AnyObject) { - SweetAlert().showAlert("Are you sure?", subTitle: "You file will permanently delete!", style: AlertStyle.Warning, buttonTitle:"Cancel", buttonColor:UIColor.colorFromRGB(0xD0D0D0) , otherButtonTitle: "Yes, delete it!", otherButtonColor: UIColor.colorFromRGB(0xDD6B55)) { (isOtherButton) -> Void in + @IBAction func warningAlert(_ sender: AnyObject) { + _ = SweetAlert().showAlert("Are you sure?", subTitle: "You file will permanently delete!", style: AlertStyle.warning, buttonTitle:"Cancel", buttonColor:UIColor.colorFromRGB(0xD0D0D0) , otherButtonTitle: "Yes, delete it!", otherButtonColor: UIColor.colorFromRGB(0xDD6B55)) { (isOtherButton) -> Void in if isOtherButton == true { print("Cancel Button Pressed", terminator: "") } else { - SweetAlert().showAlert("Deleted!", subTitle: "Your imaginary file has been deleted!", style: AlertStyle.Success) + _ = SweetAlert().showAlert("Deleted!", subTitle: "Your imaginary file has been deleted!", style: AlertStyle.success) } } } - @IBAction func cancelAndConfirm(sender: AnyObject) { - SweetAlert().showAlert("Are you sure?", subTitle: "You file will permanently delete!", style: AlertStyle.Warning, buttonTitle:"No, cancel plx!", buttonColor:UIColor.colorFromRGB(0xD0D0D0) , otherButtonTitle: "Yes, delete it!", otherButtonColor: UIColor.colorFromRGB(0xDD6B55)) { (isOtherButton) -> Void in + @IBAction func cancelAndConfirm(_ sender: AnyObject) { + _ = SweetAlert().showAlert("Are you sure?", subTitle: "You file will permanently delete!", style: AlertStyle.warning, buttonTitle:"No, cancel plx!", buttonColor:UIColor.colorFromRGB(0xD0D0D0) , otherButtonTitle: "Yes, delete it!", otherButtonColor: UIColor.colorFromRGB(0xDD6B55)) { (isOtherButton) -> Void in if isOtherButton == true { - SweetAlert().showAlert("Cancelled!", subTitle: "Your imaginary file is safe", style: AlertStyle.Error) + _ = SweetAlert().showAlert("Cancelled!", subTitle: "Your imaginary file is safe", style: AlertStyle.error) } else { - SweetAlert().showAlert("Deleted!", subTitle: "Your imaginary file has been deleted!", style: AlertStyle.Success) + _ = SweetAlert().showAlert("Deleted!", subTitle: "Your imaginary file has been deleted!", style: AlertStyle.success) } } } - @IBAction func customIconAlert(sender: AnyObject) { - SweetAlert().showAlert("Sweet!", subTitle: "Here's a custom image.", style: AlertStyle.CustomImag(imageFile: "thumb.jpg")) + @IBAction func customIconAlert(_ sender: AnyObject) { + _ = SweetAlert().showAlert("Sweet!", subTitle: "Here's a custom image.", style: AlertStyle.customImag(imageFile: "thumb.jpg")) } }