From 9e8298becc4fb42145ac69aae93aeba98ed4e5f8 Mon Sep 17 00:00:00 2001 From: Patrick Balestra Date: Wed, 15 Jun 2016 16:48:30 +0200 Subject: [PATCH 1/2] Migrated code to 3.0 Swift syntax --- .../project.pbxproj | 8 +++++- .../ParticlesLoadingView-Example.xcscheme | 2 +- .../ParticlesLoadingView/AppDelegate.swift | 12 ++++----- .../ParticlesLoadingView/ViewController.swift | 24 ++++++++--------- Example/Pods/Pods.xcodeproj/project.pbxproj | 7 +++++ Pod/Classes/EmitterCreator.swift | 14 +++++----- Pod/Classes/ParticleEffect.swift | 10 +++---- Pod/Classes/ParticlesLoadingView.swift | 12 ++++----- Pod/Classes/ParticlesScene.swift | 26 +++++++++---------- Pod/Classes/UIView+ParticlesAnimation.swift | 6 ++--- 10 files changed, 67 insertions(+), 54 deletions(-) diff --git a/Example/ParticlesLoadingView.xcodeproj/project.pbxproj b/Example/ParticlesLoadingView.xcodeproj/project.pbxproj index 4539733..77336f2 100644 --- a/Example/ParticlesLoadingView.xcodeproj/project.pbxproj +++ b/Example/ParticlesLoadingView.xcodeproj/project.pbxproj @@ -161,11 +161,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0720; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = CocoaPods; TargetAttributes = { 607FACCF1AFB9204008FA782 = { CreatedOnToolsVersion = 6.3.1; + LastSwiftMigration = 0800; }; }; }; @@ -368,6 +369,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = E4ACA28BC23E0E62601E63C9 /* Pods-ParticlesLoadingView_Example.debug.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = ParticlesLoadingView/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; @@ -386,6 +388,7 @@ PODS_FRAMEWORK_BUILD_PATH = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods-ParticlesLoadingView_Example"; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = ParticlesLoadingView_Example; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -393,6 +396,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = C5E7D085E922F5AF8C412415 /* Pods-ParticlesLoadingView_Example.release.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = ParticlesLoadingView/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; @@ -411,6 +415,8 @@ PODS_FRAMEWORK_BUILD_PATH = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods-ParticlesLoadingView_Example"; PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = ParticlesLoadingView_Example; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/Example/ParticlesLoadingView.xcodeproj/xcshareddata/xcschemes/ParticlesLoadingView-Example.xcscheme b/Example/ParticlesLoadingView.xcodeproj/xcshareddata/xcschemes/ParticlesLoadingView-Example.xcscheme index 22b96be..34f3219 100644 --- a/Example/ParticlesLoadingView.xcodeproj/xcshareddata/xcschemes/ParticlesLoadingView-Example.xcscheme +++ b/Example/ParticlesLoadingView.xcodeproj/xcshareddata/xcschemes/ParticlesLoadingView-Example.xcscheme @@ -1,6 +1,6 @@ Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> 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/Example/ParticlesLoadingView/ViewController.swift b/Example/ParticlesLoadingView/ViewController.swift index 0632f3a..f898fd2 100644 --- a/Example/ParticlesLoadingView/ViewController.swift +++ b/Example/ParticlesLoadingView/ViewController.swift @@ -16,14 +16,14 @@ class ViewController: UIViewController { @IBOutlet weak var messageView: UIView! lazy var loadingView: ParticlesLoadingView = { - let x = UIScreen.mainScreen().bounds.size.width / 2 - (75 / 2) - 200 // 🙈 - let y = UIScreen.mainScreen().bounds.size.height / 2 - (75 / 2) // 🙉 + let x = UIScreen.main().bounds.size.width / 2 - (75 / 2) - 200 // 🙈 + let y = UIScreen.main().bounds.size.height / 2 - (75 / 2) // 🙉 let view = ParticlesLoadingView(frame: CGRect(x: x, y: y, width: 75, height: 75)) - view.particleEffect = .Laser + view.particleEffect = .laser view.duration = 1.5 view.particlesSize = 15.0 view.clockwiseRotation = true - view.layer.borderColor = UIColor.lightGrayColor().CGColor + view.layer.borderColor = UIColor.lightGray().cgColor view.layer.borderWidth = 1.0 view.layer.cornerRadius = 15.0 return view @@ -38,32 +38,32 @@ class ViewController: UIViewController { // Customize view, choose the Fire effect and start the animation. messageView.layer.cornerRadius = 15.0 - messageView.layer.borderColor = UIColor.lightGrayColor().CGColor + messageView.layer.borderColor = UIColor.lightGray().cgColor messageView.layer.borderWidth = 1.0 - messageView.addParticlesAnimation(effect: ParticleEffect.Fire) + messageView.addParticlesAnimation(effect: ParticleEffect.fire) messageView.startAnimating() // Use a custom emitter particles file and customize the view. - if let emitter = NSKeyedUnarchiver.unarchiveObjectWithFile(NSBundle.mainBundle().pathForResource("Spark", ofType: "sks")!) as? SKEmitterNode { + if let emitter = NSKeyedUnarchiver.unarchiveObject(withFile: Bundle.main().pathForResource("Spark", ofType: "sks")!) as? SKEmitterNode { circleLoadingView.layer.borderWidth = 1.0 - circleLoadingView.layer.borderColor = UIColor.lightGrayColor().CGColor + circleLoadingView.layer.borderColor = UIColor.lightGray().cgColor circleLoadingView.layer.cornerRadius = circleLoadingView.frame.size.width / 2 - circleLoadingView.addParticlesAnimation(emitter) + circleLoadingView.addParticlesAnimation(with: emitter) circleLoadingView.startAnimating() } } - @IBAction func controlAnimation(sender: UIButton) { + @IBAction func controlAnimation(_ sender: UIButton) { if circleLoadingView.isEmitting() { circleLoadingView.stopAnimating() loadingView.stopAnimating() messageView.stopAnimating() - sender.setTitle("Start Animating", forState: .Normal) + sender.setTitle("Start Animating", for: UIControlState()) } else { circleLoadingView.startAnimating() loadingView.startAnimating() messageView.startAnimating() - sender.setTitle("Stop Animating", forState: .Normal) + sender.setTitle("Stop Animating", for: UIControlState()) } } } diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index c07c353..8f2c37e 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -338,6 +338,11 @@ attributes = { LastSwiftUpdateCheck = 0730; LastUpgradeCheck = 0700; + TargetAttributes = { + 3F3BA876BCA2AC1AF8AB2F6CB0059CBD = { + LastSwiftMigration = 0800; + }; + }; }; buildConfigurationList = 2D8E8EC45A3A1A1D94AE762CB5028504 /* Build configuration list for PBXProject "Pods" */; compatibilityVersion = "Xcode 3.2"; @@ -595,6 +600,7 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -662,6 +668,7 @@ PRODUCT_NAME = ParticlesLoadingView; SDKROOT = iphoneos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; diff --git a/Pod/Classes/EmitterCreator.swift b/Pod/Classes/EmitterCreator.swift index 181d9ff..6d87260 100644 --- a/Pod/Classes/EmitterCreator.swift +++ b/Pod/Classes/EmitterCreator.swift @@ -11,8 +11,8 @@ import SpriteKit public class EmitterCreator { - public enum EmitterError: ErrorType { - case EmitterNodeUnavailable + public enum EmitterError: ErrorProtocol { + case emitterNodeUnavailable } /// Creates a SKEmitterNode from one of the predefined particle emitter files. @@ -20,15 +20,15 @@ public class EmitterCreator { /// - throws: An error if the file could not be found. /// /// - returns: The emitter node object. - func createEmitterNode(effect: ParticleEffect) throws -> SKEmitterNode { - let bundle = NSBundle(forClass: self.dynamicType) + func createEmitterNode(with effect: ParticleEffect) throws -> SKEmitterNode { + let bundle = Bundle(for: self.dynamicType) let bundleName = bundle.infoDictionary!["CFBundleName"] as! String - let path = NSBundle(forClass: self.dynamicType).pathForResource(effect.rawValue, ofType: "sks", inDirectory: "\(bundleName).bundle") - if let path = path, let emitter = NSKeyedUnarchiver.unarchiveObjectWithFile(path) as? SKEmitterNode, let texture = UIImage(named: "\(bundleName).bundle/spark", inBundle: bundle, compatibleWithTraitCollection: nil) { + let path = Bundle(for: self.dynamicType).pathForResource(effect.rawValue, ofType: "sks", inDirectory: "\(bundleName).bundle") + if let path = path, let emitter = NSKeyedUnarchiver.unarchiveObject(withFile: path) as? SKEmitterNode, let texture = UIImage(named: "\(bundleName).bundle/spark", in: bundle, compatibleWith: nil) { emitter.particleTexture = SKTexture(image: texture) return emitter } else { - throw EmitterError.EmitterNodeUnavailable + throw EmitterError.emitterNodeUnavailable } } } diff --git a/Pod/Classes/ParticleEffect.swift b/Pod/Classes/ParticleEffect.swift index a79d77d..7ff0b76 100644 --- a/Pod/Classes/ParticleEffect.swift +++ b/Pod/Classes/ParticleEffect.swift @@ -9,8 +9,8 @@ import Foundation public enum ParticleEffect: String { - case Laser = "Laser" - case Spark = "Spark" - case Bokeh = "Bokeh" - case Fire = "Fire" -} \ No newline at end of file + case laser = "Laser" + case spark = "Spark" + case bokeh = "Bokeh" + case fire = "Fire" +} diff --git a/Pod/Classes/ParticlesLoadingView.swift b/Pod/Classes/ParticlesLoadingView.swift index 25e6dbb..671b144 100644 --- a/Pod/Classes/ParticlesLoadingView.swift +++ b/Pod/Classes/ParticlesLoadingView.swift @@ -36,11 +36,11 @@ public class ParticlesLoadingView: UIView { private let emitterCreator = EmitterCreator() /// The particle effect used to emit particles. - public var particleEffect = ParticleEffect.Laser { + public var particleEffect = ParticleEffect.laser { didSet { if let _ = scene { do { - let emitter = try emitterCreator.createEmitterNode(particleEffect) + let emitter = try emitterCreator.createEmitterNode(with: particleEffect) scene.setEmitterNode(emitter) } catch { fatalError("Could not find the particles file") @@ -59,20 +59,20 @@ public class ParticlesLoadingView: UIView { override public init(frame: CGRect) { super.init(frame: frame) spriteKitView = SKView(frame: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height)) - spriteKitView.backgroundColor = UIColor.clearColor() + spriteKitView.backgroundColor = UIColor.clear() setUp() } required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) spriteKitView = SKView(frame: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height)) - spriteKitView.backgroundColor = UIColor.clearColor() + spriteKitView.backgroundColor = UIColor.clear() setUp() } func setUp() { do { - let emitter = try emitterCreator.createEmitterNode(particleEffect) + let emitter = try emitterCreator.createEmitterNode(with: particleEffect) scene = ParticlesScene(size: frame.size, emitterNode: emitter) spriteKitView.presentScene(scene) addSubview(spriteKitView) @@ -97,7 +97,7 @@ public class ParticlesLoadingView: UIView { } // UIView automatically invoke this function when a view adds me as a subview. It is used to get the border path of the view. - public override func willMoveToSuperview(newSuperview: UIView?) { + public override func willMove(toSuperview newSuperview: UIView?) { scene.setAnimationPath() } diff --git a/Pod/Classes/ParticlesScene.swift b/Pod/Classes/ParticlesScene.swift index ab12df9..05a5622 100644 --- a/Pod/Classes/ParticlesScene.swift +++ b/Pod/Classes/ParticlesScene.swift @@ -14,7 +14,7 @@ public class ParticlesScene: SKScene { /// Main emitter node: modify its properties as you wish. private var emitterNode: SKEmitterNode = SKEmitterNode() { didSet { - emitterNode.position = CGPointZero + emitterNode.position = CGPoint.zero } } @@ -25,9 +25,9 @@ public class ParticlesScene: SKScene { public init(size: CGSize, emitterNode: SKEmitterNode) { self.emitterNode = emitterNode - self.emitterNode.position = CGPointMake(10, 0) + self.emitterNode.position = CGPoint(x: 10, y: 0) super.init(size: size) - backgroundColor = UIColor.clearColor() + backgroundColor = UIColor.clear() } required public init?(coder aDecoder: NSCoder) { @@ -36,7 +36,7 @@ public class ParticlesScene: SKScene { /// Set a new emitter node as the source of the particles. /// /// - parameter emitter: The object that will emit the particles. - public func setEmitterNode(emitter: SKEmitterNode) { + public func setEmitterNode(_ emitter: SKEmitterNode) { self.emitterNode = emitter } @@ -44,7 +44,7 @@ public class ParticlesScene: SKScene { func startAnimating() { emitterNode.particleBirthRate = 5000.0 emitterNode.targetNode = scene - emitterNode.runAction(loopAction, withKey: "loop") + emitterNode.run(loopAction, withKey: "loop") if emitterNode.parent == nil { addChild(emitterNode) } @@ -62,29 +62,29 @@ public class ParticlesScene: SKScene { /// Figure out the border path of the view and set it as the path of the animation. func setAnimationPath() { - var radii = CGSizeZero + var radii = CGSize.zero if let radius = view?.superview?.layer.cornerRadius { radii = CGSize(width: radius, height: radius) } let duration = (view?.superview as? ParticlesLoadingView)?.duration ?? 1.5 let particlesSize = (view?.superview as? ParticlesLoadingView)?.particlesSize ?? 5.0 if let scene = scene { - let border = UIBezierPath(roundedRect: scene.frame, byRoundingCorners: .AllCorners, cornerRadii: radii) + let border = UIBezierPath(roundedRect: scene.frame, byRoundingCorners: .allCorners, cornerRadii: radii) let horizontalInsetScaleFactor: CGFloat = 1 - (particlesSize / scene.frame.size.width) let verticalInsetScaleFactor: CGFloat = 1 - (particlesSize / scene.frame.size.height) let horizontalTranslationFactor = 2 / (1 - horizontalInsetScaleFactor) let verticalTranslationFactor = 2 / (1 - verticalInsetScaleFactor) - border.applyTransform(CGAffineTransformMakeScale(horizontalInsetScaleFactor, verticalInsetScaleFactor)) - border.applyTransform(CGAffineTransformMakeTranslation(scene.frame.size.width / horizontalTranslationFactor, scene.frame.size.height / verticalTranslationFactor)) - var followLine = SKAction.followPath(border.CGPath, asOffset: false, orientToPath: true, duration: duration) + border.apply(CGAffineTransform(scaleX: horizontalInsetScaleFactor, y: verticalInsetScaleFactor)) + border.apply(CGAffineTransform(translationX: scene.frame.size.width / horizontalTranslationFactor, y: scene.frame.size.height / verticalTranslationFactor)) + var followLine = SKAction.follow(border.cgPath, asOffset: false, orientToPath: true, duration: duration) if let superview = view?.superview as? ParticlesLoadingView { if superview.clockwiseRotation { - followLine = followLine.reversedAction() + followLine = followLine.reversed() } } - loopAction = SKAction.repeatActionForever(followLine) + loopAction = SKAction.repeatForever(followLine) } } } - \ No newline at end of file + diff --git a/Pod/Classes/UIView+ParticlesAnimation.swift b/Pod/Classes/UIView+ParticlesAnimation.swift index bb6a97b..8957f1d 100644 --- a/Pod/Classes/UIView+ParticlesAnimation.swift +++ b/Pod/Classes/UIView+ParticlesAnimation.swift @@ -14,17 +14,17 @@ public extension UIView { /// Add a particles animation with a SKEmitterNode. /// /// - parameter emitter: Emitter node object. - public func addParticlesAnimation(emitter: SKEmitterNode? = nil, effect: ParticleEffect? = nil) { + public func addParticlesAnimation(with emitter: SKEmitterNode? = nil, effect: ParticleEffect? = nil) { var spriteKitView = SKView() spriteKitView = SKView(frame: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height)) - spriteKitView.backgroundColor = UIColor.clearColor() + spriteKitView.backgroundColor = UIColor.clear() var scene: ParticlesScene if let emitter = emitter { scene = ParticlesScene(size: frame.size, emitterNode: emitter) } else if let effect = effect { do { - let emitter = try EmitterCreator().createEmitterNode(effect) + let emitter = try EmitterCreator().createEmitterNode(with: effect) scene = ParticlesScene(size: frame.size, emitterNode: emitter) } catch { fatalError("The default ParticleEffect could not be loaded.") From 939cdf409cf0f74fdfdd39afe4f4f837d6f4f90d Mon Sep 17 00:00:00 2001 From: Patrick Balestra Date: Sat, 1 Oct 2016 14:40:38 +0200 Subject: [PATCH 2/2] Update to last Swift 3 syntax --- .../ParticlesLoadingView.xcodeproj/project.pbxproj | 6 +++++- .../xcschemes/ParticlesLoadingView-Example.xcscheme | 2 +- Example/ParticlesLoadingView/AppDelegate.swift | 4 +--- Example/ParticlesLoadingView/ViewController.swift | 12 ++++++------ Pod/Classes/EmitterCreator.swift | 6 +++--- Pod/Classes/ParticlesLoadingView.swift | 4 ++-- Pod/Classes/ParticlesScene.swift | 2 +- Pod/Classes/UIView+ParticlesAnimation.swift | 2 +- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Example/ParticlesLoadingView.xcodeproj/project.pbxproj b/Example/ParticlesLoadingView.xcodeproj/project.pbxproj index 77336f2..6fc6297 100644 --- a/Example/ParticlesLoadingView.xcodeproj/project.pbxproj +++ b/Example/ParticlesLoadingView.xcodeproj/project.pbxproj @@ -161,7 +161,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0810; ORGANIZATIONNAME = CocoaPods; TargetAttributes = { 607FACCF1AFB9204008FA782 = { @@ -296,8 +296,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"; @@ -341,8 +343,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"; diff --git a/Example/ParticlesLoadingView.xcodeproj/xcshareddata/xcschemes/ParticlesLoadingView-Example.xcscheme b/Example/ParticlesLoadingView.xcodeproj/xcshareddata/xcschemes/ParticlesLoadingView-Example.xcscheme index 34f3219..ebb6772 100644 --- a/Example/ParticlesLoadingView.xcodeproj/xcshareddata/xcschemes/ParticlesLoadingView-Example.xcscheme +++ b/Example/ParticlesLoadingView.xcodeproj/xcshareddata/xcschemes/ParticlesLoadingView-Example.xcscheme @@ -1,6 +1,6 @@ Bool { - // Override point for customization after application launch. + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { return true } diff --git a/Example/ParticlesLoadingView/ViewController.swift b/Example/ParticlesLoadingView/ViewController.swift index f898fd2..d6662af 100644 --- a/Example/ParticlesLoadingView/ViewController.swift +++ b/Example/ParticlesLoadingView/ViewController.swift @@ -16,14 +16,14 @@ class ViewController: UIViewController { @IBOutlet weak var messageView: UIView! lazy var loadingView: ParticlesLoadingView = { - let x = UIScreen.main().bounds.size.width / 2 - (75 / 2) - 200 // 🙈 - let y = UIScreen.main().bounds.size.height / 2 - (75 / 2) // 🙉 + let x = UIScreen.main.bounds.size.width / 2 - (75 / 2) - 200 // 🙈 + let y = UIScreen.main.bounds.size.height / 2 - (75 / 2) // 🙉 let view = ParticlesLoadingView(frame: CGRect(x: x, y: y, width: 75, height: 75)) view.particleEffect = .laser view.duration = 1.5 view.particlesSize = 15.0 view.clockwiseRotation = true - view.layer.borderColor = UIColor.lightGray().cgColor + view.layer.borderColor = UIColor.lightGray.cgColor view.layer.borderWidth = 1.0 view.layer.cornerRadius = 15.0 return view @@ -38,15 +38,15 @@ class ViewController: UIViewController { // Customize view, choose the Fire effect and start the animation. messageView.layer.cornerRadius = 15.0 - messageView.layer.borderColor = UIColor.lightGray().cgColor + messageView.layer.borderColor = UIColor.lightGray.cgColor messageView.layer.borderWidth = 1.0 messageView.addParticlesAnimation(effect: ParticleEffect.fire) messageView.startAnimating() // Use a custom emitter particles file and customize the view. - if let emitter = NSKeyedUnarchiver.unarchiveObject(withFile: Bundle.main().pathForResource("Spark", ofType: "sks")!) as? SKEmitterNode { + if let emitter = NSKeyedUnarchiver.unarchiveObject(withFile: Bundle.main.path(forResource: "Spark", ofType: "sks")!) as? SKEmitterNode { circleLoadingView.layer.borderWidth = 1.0 - circleLoadingView.layer.borderColor = UIColor.lightGray().cgColor + circleLoadingView.layer.borderColor = UIColor.lightGray.cgColor circleLoadingView.layer.cornerRadius = circleLoadingView.frame.size.width / 2 circleLoadingView.addParticlesAnimation(with: emitter) circleLoadingView.startAnimating() diff --git a/Pod/Classes/EmitterCreator.swift b/Pod/Classes/EmitterCreator.swift index 6d87260..61434cf 100644 --- a/Pod/Classes/EmitterCreator.swift +++ b/Pod/Classes/EmitterCreator.swift @@ -11,7 +11,7 @@ import SpriteKit public class EmitterCreator { - public enum EmitterError: ErrorProtocol { + public enum EmitterError: Error { case emitterNodeUnavailable } @@ -21,9 +21,9 @@ public class EmitterCreator { /// /// - returns: The emitter node object. func createEmitterNode(with effect: ParticleEffect) throws -> SKEmitterNode { - let bundle = Bundle(for: self.dynamicType) + let bundle = Bundle(for: type(of: self)) let bundleName = bundle.infoDictionary!["CFBundleName"] as! String - let path = Bundle(for: self.dynamicType).pathForResource(effect.rawValue, ofType: "sks", inDirectory: "\(bundleName).bundle") + let path = Bundle(for: type(of: self)).path(forResource: effect.rawValue, ofType: "sks", inDirectory: "\(bundleName).bundle") if let path = path, let emitter = NSKeyedUnarchiver.unarchiveObject(withFile: path) as? SKEmitterNode, let texture = UIImage(named: "\(bundleName).bundle/spark", in: bundle, compatibleWith: nil) { emitter.particleTexture = SKTexture(image: texture) return emitter diff --git a/Pod/Classes/ParticlesLoadingView.swift b/Pod/Classes/ParticlesLoadingView.swift index 671b144..737a0f2 100644 --- a/Pod/Classes/ParticlesLoadingView.swift +++ b/Pod/Classes/ParticlesLoadingView.swift @@ -59,14 +59,14 @@ public class ParticlesLoadingView: UIView { override public init(frame: CGRect) { super.init(frame: frame) spriteKitView = SKView(frame: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height)) - spriteKitView.backgroundColor = UIColor.clear() + spriteKitView.backgroundColor = UIColor.clear setUp() } required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) spriteKitView = SKView(frame: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height)) - spriteKitView.backgroundColor = UIColor.clear() + spriteKitView.backgroundColor = UIColor.clear setUp() } diff --git a/Pod/Classes/ParticlesScene.swift b/Pod/Classes/ParticlesScene.swift index 05a5622..907c94a 100644 --- a/Pod/Classes/ParticlesScene.swift +++ b/Pod/Classes/ParticlesScene.swift @@ -27,7 +27,7 @@ public class ParticlesScene: SKScene { self.emitterNode = emitterNode self.emitterNode.position = CGPoint(x: 10, y: 0) super.init(size: size) - backgroundColor = UIColor.clear() + backgroundColor = UIColor.clear } required public init?(coder aDecoder: NSCoder) { diff --git a/Pod/Classes/UIView+ParticlesAnimation.swift b/Pod/Classes/UIView+ParticlesAnimation.swift index 8957f1d..3b0cbea 100644 --- a/Pod/Classes/UIView+ParticlesAnimation.swift +++ b/Pod/Classes/UIView+ParticlesAnimation.swift @@ -17,7 +17,7 @@ public extension UIView { public func addParticlesAnimation(with emitter: SKEmitterNode? = nil, effect: ParticleEffect? = nil) { var spriteKitView = SKView() spriteKitView = SKView(frame: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height)) - spriteKitView.backgroundColor = UIColor.clear() + spriteKitView.backgroundColor = UIColor.clear var scene: ParticlesScene if let emitter = emitter {