From 807024db214f8aa6aef9ee18d48150b55dc23110 Mon Sep 17 00:00:00 2001 From: Kyle Yi Date: Sat, 24 Oct 2026 14:41:37 +0900 Subject: [PATCH 1/2] Build on current Swift/Xcode: Swift 4.2+ API names, @objc selector, public init Found while vendoring the library into MotionBook 3.5 (iOS reference app that runs library demos live); verified by building the package/file on Xcode 27.1. --- SweetAlert/SweetAlert.swift | 48 ++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/SweetAlert/SweetAlert.swift b/SweetAlert/SweetAlert.swift index 6c7b30a..9fb572b 100644 --- a/SweetAlert/SweetAlert.swift +++ b/SweetAlert/SweetAlert.swift @@ -36,10 +36,10 @@ open class SweetAlert: UIViewController { var userAction:((_ isOtherButton: Bool) -> Void)? = nil let kFont = "Helvetica" - init() { + public init() { super.init(nibName: nil, bundle: nil) self.view.frame = UIScreen.main.bounds - self.view.autoresizingMask = [UIViewAutoresizing.flexibleHeight, UIViewAutoresizing.flexibleWidth] + self.view.autoresizingMask = [UIView.AutoresizingMask.flexibleHeight, UIView.AutoresizingMask.flexibleWidth] self.view.backgroundColor = UIColor(red:0, green:0, blue:0, alpha:kBakcgroundTansperancy) self.view.addSubview(contentView) @@ -108,7 +108,7 @@ open class SweetAlert: UIViewController { // Subtitle if self.subTitleTextView.text.isEmpty == false { let subtitleString = subTitleTextView.text! as NSString - let rect = subtitleString.boundingRect(with: 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: [NSAttributedString.Key.font: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 @@ open class SweetAlert: UIViewController { var buttonRect:[CGRect] = [] for button in buttons { - 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)) + let string = button.title(for: UIControl.State())! as NSString + buttonRect.append(string.boundingRect(with: CGSize(width: width, height:0.0), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes:[NSAttributedString.Key.font:button.titleLabel!.font], context:nil)) } var totalWidth: CGFloat = 0.0 @@ -136,7 +136,7 @@ open class SweetAlert: UIViewController { 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: #selector(SweetAlert.pressed(_:)), for: UIControlEvents.touchUpInside) + buttons[i].addTarget(self, action: #selector(SweetAlert.pressed(_:)), for: UIControl.Event.touchUpInside) } y += kHeightMargin + buttonRect[0].size.height + 10.0 @@ -157,7 +157,7 @@ open class SweetAlert: UIViewController { contentView.clipsToBounds = true } - open func pressed(_ sender: UIButton!) { + @objc open func pressed(_ sender: UIButton!) { self.closeAlert(sender.tag) } @@ -168,7 +168,7 @@ open class SweetAlert: UIViewController { 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.shared.statusBarOrientation) { + if UIApplication.shared.statusBarOrientation.isLandscape { let ssz = sz sz = CGSize(width:ssz.height, height:ssz.width) } @@ -184,7 +184,7 @@ open class SweetAlert: UIViewController { SweetAlertContext.shouldNotAnimate = false } - UIView.animate(withDuration: 0.5, delay: 0.0, options: UIViewAnimationOptions.curveEaseOut, animations: { () -> Void in + UIView.animate(withDuration: 0.5, delay: 0.0, options: UIView.AnimationOptions.curveEaseOut, animations: { () -> Void in self.view.alpha = 0.0 }) { (Bool) -> Void in self.view.removeFromSuperview() @@ -242,7 +242,7 @@ open class SweetAlert: UIViewController { userAction = action let window: UIWindow = UIApplication.shared.keyWindow! window.addSubview(view) - window.bringSubview(toFront: view) + window.bringSubviewToFront(view) view.frame = window.bounds self.setupContentView() self.setupTitleLabel() @@ -272,8 +272,8 @@ open class SweetAlert: UIViewController { } buttons = [] if buttonTitle.isEmpty == false { - let button: UIButton = UIButton(type: UIButtonType.custom) - button.setTitle(buttonTitle, for: UIControlState()) + let button: UIButton = UIButton(type: UIButton.ButtonType.custom) + button.setTitle(buttonTitle, for: UIControl.State()) button.backgroundColor = buttonColor button.isUserInteractionEnabled = true button.tag = 0 @@ -281,10 +281,10 @@ open class SweetAlert: UIViewController { } if otherButtonTitle != nil && otherButtonTitle!.isEmpty == false { - let button: UIButton = UIButton(type: UIButtonType.custom) - button.setTitle(otherButtonTitle, for: UIControlState()) + let button: UIButton = UIButton(type: UIButton.ButtonType.custom) + button.setTitle(otherButtonTitle, for: UIControl.State()) button.backgroundColor = otherButtonColor - button.addTarget(self, action: #selector(SweetAlert.pressed(_:)), for: UIControlEvents.touchUpInside) + button.addTarget(self, action: #selector(SweetAlert.pressed(_:)), for: UIControl.Event.touchUpInside) button.tag = 1 buttons.append(button) } @@ -392,7 +392,7 @@ class CancelAnimatedView: AnimatableView { circleLayer.path = outlineCircle circleLayer.fillColor = UIColor.clear.cgColor; circleLayer.strokeColor = UIColor.colorFromRGB(0xF27474).cgColor; - circleLayer.lineCap = kCALineCapRound + circleLayer.lineCap = CAShapeLayerLineCap.round circleLayer.lineWidth = 4; circleLayer.frame = CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height) circleLayer.position = CGPoint(x: self.frame.size.width/2.0, y: self.frame.size.height/2.0) @@ -401,7 +401,7 @@ class CancelAnimatedView: AnimatableView { crossPathLayer.path = crossPath crossPathLayer.fillColor = UIColor.clear.cgColor; crossPathLayer.strokeColor = UIColor.colorFromRGB(0xF27474).cgColor; - crossPathLayer.lineCap = kCALineCapRound + crossPathLayer.lineCap = CAShapeLayerLineCap.round crossPathLayer.lineWidth = 4; crossPathLayer.frame = CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height) crossPathLayer.position = CGPoint(x: self.frame.size.width/2.0, y: self.frame.size.height/2.0) @@ -424,7 +424,7 @@ class CancelAnimatedView: AnimatableView { animation.fromValue = NSValue(caTransform3D: t) animation.toValue = NSValue(caTransform3D:t2) animation.isRemovedOnCompletion = false - animation.fillMode = kCAFillModeForwards + animation.fillMode = CAMediaTimingFillMode.forwards self.circleLayer.add(animation, forKey: "transform") @@ -446,7 +446,7 @@ class CancelAnimatedView: AnimatableView { fadeInAnimation.fromValue = 0.3 fadeInAnimation.toValue = 1.0 fadeInAnimation.isRemovedOnCompletion = false - fadeInAnimation.fillMode = kCAFillModeForwards + fadeInAnimation.fillMode = CAMediaTimingFillMode.forwards self.crossPathLayer.add(fadeInAnimation, forKey: "opacity") } @@ -489,7 +489,7 @@ class InfoAnimatedView: AnimatableView { circleLayer.path = outlineCircle circleLayer.fillColor = UIColor.clear.cgColor; circleLayer.strokeColor = UIColor.colorFromRGB(0xF8D486).cgColor; - circleLayer.lineCap = kCALineCapRound + circleLayer.lineCap = CAShapeLayerLineCap.round circleLayer.lineWidth = 4; circleLayer.frame = CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height) circleLayer.position = CGPoint(x: self.frame.size.width/2.0, y: self.frame.size.height/2.0) @@ -501,7 +501,7 @@ class InfoAnimatedView: AnimatableView { let colorAnimation = CABasicAnimation(keyPath:"strokeColor") colorAnimation.duration = 1.0; colorAnimation.repeatCount = HUGE - colorAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) + colorAnimation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut) colorAnimation.autoreverses = true colorAnimation.fromValue = UIColor.colorFromRGB(0xF7D58B).cgColor colorAnimation.toValue = UIColor.colorFromRGB(0xF2A665).cgColor @@ -557,7 +557,7 @@ class SuccessAnimatedView: AnimatableView { outlineLayer.path = outlineCircle 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.lineCap = CAShapeLayerLineCap.round outlineLayer.lineWidth = 4; outlineLayer.opacity = 0.1 self.layer.addSublayer(outlineLayer) @@ -567,7 +567,7 @@ class SuccessAnimatedView: AnimatableView { circleLayer.path = path 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.lineCap = CAShapeLayerLineCap.round circleLayer.lineWidth = 4; circleLayer.actions = [ "strokeStart": NSNull(), @@ -591,7 +591,7 @@ class SuccessAnimatedView: AnimatableView { strokeStart.toValue = 0.68 strokeStart.duration = 7.0*factor strokeStart.beginTime = CACurrentMediaTime() + 3.0*factor - strokeStart.fillMode = kCAFillModeBackwards + strokeStart.fillMode = CAMediaTimingFillMode.backwards strokeStart.timingFunction = timing circleLayer.strokeStart = 0.68 circleLayer.strokeEnd = 0.93 From e028c8bd11fd00763d65d1f09816995b67a3e145 Mon Sep 17 00:00:00 2001 From: Kyle Yi Date: Sat, 24 Oct 2026 14:50:55 +0900 Subject: [PATCH 2/2] Add Swift Package Manager support --- Package.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Package.swift diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..107867d --- /dev/null +++ b/Package.swift @@ -0,0 +1,19 @@ +// swift-tools-version:5.5 +import PackageDescription + +let package = Package( + name: "SweetAlert", + platforms: [.iOS(.v12)], + products: [ + .library(name: "SweetAlert", targets: ["SweetAlert"]) + ], + targets: [ + .target( + name: "SweetAlert", + path: "SweetAlert", + exclude: ["AppDelegate.swift", "ViewController.swift", "Base.lproj", "Images.xcassets", "Info.plist", "logo_big.png", "SweetAlert.png"], + sources: ["SweetAlert.swift"] + ) + ], + swiftLanguageVersions: [.v5] +)