diff --git a/Demo/Podfile.lock b/Demo/Podfile.lock index 27497f5..fd96a96 100644 --- a/Demo/Podfile.lock +++ b/Demo/Podfile.lock @@ -9,8 +9,8 @@ EXTERNAL SOURCES: :path: "../" SPEC CHECKSUMS: - TimedSilver: 9a4db36b50fe8dd2f76ec28a1d5b6f0e98f6bb30 + TimedSilver: d811b891a5a3db4655bbfcb017313abfaa0e36ab PODFILE CHECKSUM: 416a9304df26078601f30ee2451b2f3dbe8abf38 -COCOAPODS: 1.2.0 +COCOAPODS: 1.5.3 diff --git a/Demo/TimedSilverExample.xcodeproj/project.pbxproj b/Demo/TimedSilverExample.xcodeproj/project.pbxproj index fe77b07..ff92938 100644 --- a/Demo/TimedSilverExample.xcodeproj/project.pbxproj +++ b/Demo/TimedSilverExample.xcodeproj/project.pbxproj @@ -132,7 +132,6 @@ AEBAE9391D8E8AF200CFDBD5 /* Frameworks */, AEBAE93A1D8E8AF200CFDBD5 /* Resources */, ED52BC296B9EF83249163349 /* [CP] Embed Pods Frameworks */, - 201A5143EF5307CE6CDE43D3 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -230,28 +229,16 @@ files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-TimedSilverExample-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; - showEnvVarsInLog = 0; - }; - 201A5143EF5307CE6CDE43D3 /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-TimedSilverExample/Pods-TimedSilverExample-resources.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; ED52BC296B9EF83249163349 /* [CP] Embed Pods Frameworks */ = { @@ -260,9 +247,12 @@ files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-TimedSilverExample/Pods-TimedSilverExample-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/TimedSilver/TimedSilver.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/TimedSilver.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -433,7 +423,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = Hilen.TimedSilverExample; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -446,7 +436,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = Hilen.TimedSilverExample; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/Demo/TimedSilverExample/AppDelegate.swift b/Demo/TimedSilverExample/AppDelegate.swift index 7b2e24c..e07a708 100644 --- a/Demo/TimedSilverExample/AppDelegate.swift +++ b/Demo/TimedSilverExample/AppDelegate.swift @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } diff --git a/Demo/TimedSilverExample/ViewController.swift b/Demo/TimedSilverExample/ViewController.swift index ad92679..0e7fd59 100644 --- a/Demo/TimedSilverExample/ViewController.swift +++ b/Demo/TimedSilverExample/ViewController.swift @@ -15,6 +15,7 @@ class ViewController: UIViewController { super.viewDidLoad() print(UIViewController.ts_className) // Do any additional setup after loading the view, typically from a nib. + self.view.backgroundColor = UIColor.red; } override func didReceiveMemoryWarning() { diff --git a/Sources/Foundation/Timer+TSBlock.swift b/Sources/Foundation/Timer+TSBlock.swift index a10780c..687939d 100644 --- a/Sources/Foundation/Timer+TSBlock.swift +++ b/Sources/Foundation/Timer+TSBlock.swift @@ -90,8 +90,8 @@ extension Timer { /// By default, the timer is scheduled on the current run loop for the default mode. /// Specify `runLoop` or `modes` to override these defaults. - public func ts_start(runLoop: RunLoop = RunLoop.current, modes: RunLoopMode...) { - let modes = modes.isEmpty ? [RunLoopMode.defaultRunLoopMode] : modes + public func ts_start(runLoop: RunLoop = RunLoop.current, modes: RunLoop.Mode...) { + let modes = modes.isEmpty ? [RunLoop.Mode.default] : modes for mode in modes { runLoop.add(self, forMode: mode) diff --git a/Sources/Struct/String+TSExtension.swift b/Sources/Struct/String+TSExtension.swift index a959939..1926ca9 100644 --- a/Sources/Struct/String+TSExtension.swift +++ b/Sources/Struct/String+TSExtension.swift @@ -29,7 +29,7 @@ public extension String { let size: CGSize = self.boundingRect( with: constraintRect, options: NSStringDrawingOptions.usesLineFragmentOrigin, - attributes: [NSAttributedStringKey.font: font], + attributes: [NSAttributedString.Key.font: font], context: nil ).size return size @@ -48,7 +48,7 @@ public extension String { let boundingBox = self.boundingRect( with: constraintRect, options: .usesLineFragmentOrigin, - attributes: [NSAttributedStringKey.font: font], + attributes: [NSAttributedString.Key.font: font], context: nil) return boundingBox.height } @@ -65,7 +65,7 @@ public extension String { let boundingBox = self.boundingRect( with: constraintRect, options: .usesLineFragmentOrigin, - attributes: [NSAttributedStringKey.font: font], + attributes: [NSAttributedString.Key.font: font], context: nil) return boundingBox.width } diff --git a/Sources/UIKit/UIButton+TSExtension.swift b/Sources/UIKit/UIButton+TSExtension.swift index 8b07ec8..5ccaab8 100644 --- a/Sources/UIKit/UIButton+TSExtension.swift +++ b/Sources/UIKit/UIButton+TSExtension.swift @@ -16,7 +16,7 @@ public extension UIButton { - parameter color: color - parameter forState: UIControlState */ - public func ts_setBackgroundColor(_ color: UIColor, forState: UIControlState) { + public func ts_setBackgroundColor(_ color: UIColor, forState: UIControl.State) { UIGraphicsBeginImageContext(CGSize(width: 1, height: 1)) UIGraphicsGetCurrentContext()?.setFillColor(color.cgColor) UIGraphicsGetCurrentContext()?.fill(CGRect(x: 0, y: 0, width: 1, height: 1)) diff --git a/Sources/UIKit/UIButton+TSTouchArea.swift b/Sources/UIKit/UIButton+TSTouchArea.swift index 5e059ae..ad9dcd8 100644 --- a/Sources/UIKit/UIButton+TSTouchArea.swift +++ b/Sources/UIKit/UIButton+TSTouchArea.swift @@ -39,8 +39,8 @@ extension UIButton { } let relativeFrame = self.bounds - let hitFrame = UIEdgeInsetsInsetRect(relativeFrame, self.ts_touchInsets) - +// let hitFrame = UIEdgeInsetsInsetRect(relativeFrame, self.ts_touchInsets) + let hitFrame = relativeFrame.inset(by: self.ts_touchInsets) return hitFrame.contains(point) } } diff --git a/Sources/UIKit/UICollectionView+TSGeneric.swift b/Sources/UIKit/UICollectionView+TSGeneric.swift index 03340d8..4f3a341 100644 --- a/Sources/UIKit/UICollectionView+TSGeneric.swift +++ b/Sources/UIKit/UICollectionView+TSGeneric.swift @@ -58,7 +58,7 @@ public extension UICollectionView { func ts_registerHeaderNib(_ aClass: T.Type) { let name = String(describing: aClass) let nib = UINib(nibName: name, bundle: nil) - self.register(nib, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: name) + self.register(nib, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: name) } /** @@ -68,7 +68,7 @@ public extension UICollectionView { */ func ts_registerHeaderClass(_ aClass: T.Type) { let name = String(describing: aClass) - self.register(aClass, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: name) + self.register(aClass, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: name) } /** @@ -82,7 +82,7 @@ public extension UICollectionView { func ts_dequeueReusableHeader(_ aClass: T.Type, forIndexPath indexPath: IndexPath) -> T! { let name = String(describing: aClass) guard let view = dequeueReusableSupplementaryView( - ofKind: UICollectionElementKindSectionHeader, + ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: name, for: indexPath) as? T else { fatalError("\(name) is not registed") @@ -99,7 +99,7 @@ public extension UICollectionView { func ts_registerFooterNib(_ aClass: T.Type) { let name = String(describing: aClass) let nib = UINib(nibName: name, bundle: nil) - self.register(nib, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: name) + self.register(nib, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: name) } /** @@ -109,7 +109,7 @@ public extension UICollectionView { */ func ts_registerFooterClass(_ aClass: T.Type) { let name = String(describing: aClass) - self.register(aClass, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: name) + self.register(aClass, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: name) } /** @@ -123,7 +123,7 @@ public extension UICollectionView { func ts_dequeueReusableFooter(_ aClass: T.Type, forIndexPath indexPath: IndexPath) -> T! { let name = String(describing: aClass) guard let view = dequeueReusableSupplementaryView( - ofKind: UICollectionElementKindSectionFooter, + ofKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: name, for: indexPath) as? T else { fatalError("\(name) is not registed") diff --git a/Sources/UIKit/UIControl+TSExtension.swift b/Sources/UIKit/UIControl+TSExtension.swift index 12d9f08..5d81572 100644 --- a/Sources/UIKit/UIControl+TSExtension.swift +++ b/Sources/UIKit/UIControl+TSExtension.swift @@ -32,7 +32,7 @@ public extension UIControl { - parameter events: UIControlEvents - parameter callback: callback */ - func ts_addEventHandler(forControlEvent controlEvent: UIControlEvents, handler callback: @escaping () -> Void) { + func ts_addEventHandler(forControlEvent controlEvent: UIControl.Event, handler callback: @escaping () -> Void) { let wrapper = TSClosureWrapper(callback: callback) addTarget(wrapper, action:#selector(TSClosureWrapper.invoke), for: controlEvent) objc_setAssociatedObject(self, &AssociatedClosure, wrapper, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) diff --git a/Sources/UIKit/UIControl+TSSound.swift b/Sources/UIKit/UIControl+TSSound.swift index ba2540a..f3a8bd0 100644 --- a/Sources/UIKit/UIControl+TSSound.swift +++ b/Sources/UIKit/UIControl+TSSound.swift @@ -22,13 +22,20 @@ extension UIControl { - parameter name: music name - parameter controlEvent: controlEvent */ - public func ts_addSoundName(_ name: String, forControlEvent controlEvent: UIControlEvents) { + public func ts_addSoundName(_ name: String, forControlEvent controlEvent: UIControl.Event) { let oldSoundKey: String = "\(controlEvent)" let oldSound: AVAudioPlayer = self.ts_sounds[oldSoundKey]! let selector = NSSelectorFromString("play") self.removeTarget(oldSound, action: selector, for: controlEvent) do { - try AVAudioSession.sharedInstance().setCategory("AVAudioSessionCategoryAmbient") + if #available(iOS 10.0, *) { + try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.ambient, mode: AVAudioSession.Mode.default, options: AVAudioSession.CategoryOptions.defaultToSpeaker) + } else { + // Fallback on earlier versions +// try AVAudioSession.sharedInstance().setCategory("AVAudioSessionCategoryAmbient") + } +// + // Find the sound file. guard let soundFileURL = Bundle.main.url(forResource: name, withExtension: "") else { assert(false, "File not exist") diff --git a/Sources/UIKit/UIImage+TSOrientation.swift b/Sources/UIKit/UIImage+TSOrientation.swift index 49f2ed8..20f410d 100644 --- a/Sources/UIKit/UIImage+TSOrientation.swift +++ b/Sources/UIKit/UIImage+TSOrientation.swift @@ -25,38 +25,38 @@ public extension UIImage { */ class func ts_fixImageOrientation(_ src:UIImage) -> UIImage { - if src.imageOrientation == UIImageOrientation.up { + if src.imageOrientation == UIImage.Orientation.up { return src } var transform: CGAffineTransform = CGAffineTransform.identity switch src.imageOrientation { - case UIImageOrientation.down, UIImageOrientation.downMirrored: + case UIImage.Orientation.down, UIImage.Orientation.downMirrored: transform = transform.translatedBy(x: src.size.width, y: src.size.height) transform = transform.rotated(by: CGFloat(Double.pi)) break - case UIImageOrientation.left, UIImageOrientation.leftMirrored: + case UIImage.Orientation.left, UIImage.Orientation.leftMirrored: transform = transform.translatedBy(x: src.size.width, y: 0) transform = transform.rotated(by: CGFloat(Double.pi)) break - case UIImageOrientation.right, UIImageOrientation.rightMirrored: + case UIImage.Orientation.right, UIImage.Orientation.rightMirrored: transform = transform.translatedBy(x: 0, y: src.size.height) transform = transform.rotated(by: CGFloat(-Double.pi)) break - case UIImageOrientation.up, UIImageOrientation.upMirrored: + case UIImage.Orientation.up, UIImage.Orientation.upMirrored: break } switch src.imageOrientation { - case UIImageOrientation.upMirrored, UIImageOrientation.downMirrored: + case UIImage.Orientation.upMirrored, UIImage.Orientation.downMirrored: transform.translatedBy(x: src.size.width, y: 0) transform.scaledBy(x: -1, y: 1) break - case UIImageOrientation.leftMirrored, UIImageOrientation.rightMirrored: + case UIImage.Orientation.leftMirrored, UIImage.Orientation.rightMirrored: transform.translatedBy(x: src.size.height, y: 0) transform.scaledBy(x: -1, y: 1) - case UIImageOrientation.up, UIImageOrientation.down, UIImageOrientation.left, UIImageOrientation.right: + case UIImage.Orientation.up, UIImage.Orientation.down, UIImage.Orientation.left, UIImage.Orientation.right: break } @@ -65,7 +65,7 @@ public extension UIImage { ctx.concatenate(transform) switch src.imageOrientation { - case UIImageOrientation.left, UIImageOrientation.leftMirrored, UIImageOrientation.right, UIImageOrientation.rightMirrored: + case UIImage.Orientation.left, UIImage.Orientation.leftMirrored, UIImage.Orientation.right, UIImage.Orientation.rightMirrored: ctx.draw(src.cgImage!, in: CGRect(x: 0, y: 0, width: src.size.height, height: src.size.width)) break default: diff --git a/Sources/UIKit/UILabel+TSExtension.swift b/Sources/UIKit/UILabel+TSExtension.swift index cb70943..0afe63f 100644 --- a/Sources/UIKit/UILabel+TSExtension.swift +++ b/Sources/UIKit/UILabel+TSExtension.swift @@ -20,7 +20,7 @@ public extension UILabel { let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.lineBreakMode = self.lineBreakMode paragraphStyle.alignment = self.textAlignment - let attributes: [NSAttributedStringKey : AnyObject] = [ + let attributes: [NSAttributedString.Key : AnyObject] = [ .font: self.font, .paragraphStyle: paragraphStyle] let contentSize: CGSize = self.text!.boundingRect( @@ -40,7 +40,7 @@ public extension UILabel { */ func ts_setFrameWithString(_ string: String, width: CGFloat) { self.numberOfLines = 0 - let attributes: [NSAttributedStringKey : AnyObject] = [ + let attributes: [NSAttributedString.Key : AnyObject] = [ .font: self.font, ] let resultSize: CGSize = string.boundingRect( diff --git a/Sources/UIKit/UINavigationController+TSExtension.swift b/Sources/UIKit/UINavigationController+TSExtension.swift index cb1e159..57a69e9 100644 --- a/Sources/UIKit/UINavigationController+TSExtension.swift +++ b/Sources/UIKit/UINavigationController+TSExtension.swift @@ -16,7 +16,7 @@ extension UINavigationController { - parameter controller: target viewController - parameter transition: UIViewAnimationTransition */ - public func ts_pushViewController(_ controller: UIViewController, transition: UIViewAnimationTransition) { + public func ts_pushViewController(_ controller: UIViewController, transition: UIView.AnimationTransition) { UIView.beginAnimations(nil, context: nil) self.pushViewController(controller, animated: false) UIView.setAnimationDuration(0.5) @@ -33,7 +33,7 @@ extension UINavigationController { - returns: UIViewController */ - public func ts_popViewController(_ controller: UIViewController, transition: UIViewAnimationTransition) -> UIViewController { + public func ts_popViewController(_ controller: UIViewController, transition: UIView.AnimationTransition) -> UIViewController { UIView.beginAnimations(nil, context: nil) let controller = self.popViewController(animated: false) UIView.setAnimationDuration(0.5) diff --git a/Sources/UIKit/UINavigationItem+TSExtension.swift b/Sources/UIKit/UINavigationItem+TSExtension.swift index ed65708..06137d7 100644 --- a/Sources/UIKit/UINavigationItem+TSExtension.swift +++ b/Sources/UIKit/UINavigationItem+TSExtension.swift @@ -59,15 +59,15 @@ public extension UINavigationItem { - returns: Item button */ class func ts_itemButton(_ image: UIImage? = nil, text: String? = nil) -> UIButton { - let button: UIButton = UIButton(type: UIButtonType.custom) + let button: UIButton = UIButton(type: UIButton.ButtonType.custom) if let aImage = image { - button.setImage(aImage, for: UIControlState()) + button.setImage(aImage, for: UIControl.State()) } var buttonWidth: CGFloat = 40 if let aText = text { button.titleLabel?.font = UIFont.systemFont(ofSize: 16) - let attributes: [NSAttributedStringKey : AnyObject] = [ + let attributes: [NSAttributedString.Key : AnyObject] = [ .font: button.titleLabel!.font, ] let size: CGSize = aText.boundingRect( @@ -78,7 +78,7 @@ public extension UINavigationItem { ).size buttonWidth = size.width - button.setTitle(aText, for: UIControlState()) + button.setTitle(aText, for: UIControl.State()) } button.imageView!.contentMode = .scaleAspectFit; button.frame = CGRect(x: 0, y: 0, width: buttonWidth, height: 30) diff --git a/Sources/UIKit/UIScreen+TSExtension.swift b/Sources/UIKit/UIScreen+TSExtension.swift index 984c093..546b2ad 100644 --- a/Sources/UIKit/UIScreen+TSExtension.swift +++ b/Sources/UIKit/UIScreen+TSExtension.swift @@ -33,7 +33,8 @@ public extension UIScreen { return CGSize.zero } let systemVersion = (UIDevice.current.systemVersion as NSString).floatValue - let isLand: Bool = UIInterfaceOrientationIsLandscape(app.statusBarOrientation) + let isLand: Bool = UIInterfaceOrientation.landscapeLeft == app.statusBarOrientation || UIInterfaceOrientation.landscapeRight == app.statusBarOrientation +// UIInterfaceOrientationIsLandscape(app.statusBarOrientation) return (systemVersion > 8.0 && isLand) ? UIScreen.ts_swapSize(self.ts_size) : self.ts_size } @@ -71,7 +72,8 @@ public extension UIScreen { guard let app = UIApplication.ts_sharedApplication() else { return 0 } - if UIInterfaceOrientationIsPortrait(app.statusBarOrientation) { + + if UIInterfaceOrientation.portrait == app.statusBarOrientation { return UIScreen.main.bounds.size.height - app.statusBarFrame.height } else { return UIScreen.main.bounds.size.width - app.statusBarFrame.height diff --git a/Sources/UIKit/UIViewController+TSExtension.swift b/Sources/UIKit/UIViewController+TSExtension.swift index 1ad335d..5114c35 100644 --- a/Sources/UIKit/UIViewController+TSExtension.swift +++ b/Sources/UIKit/UIViewController+TSExtension.swift @@ -47,8 +47,8 @@ public extension UIViewController { return } - let button: UIButton = UIButton(type: UIButtonType.custom) - button.setImage(backImage, for: UIControlState()) + let button: UIButton = UIButton(type: UIButton.ButtonType.custom) + button.setImage(backImage, for: UIControl.State()) button.frame = CGRect(x: 0, y: 0, width: 40, height: 30) button.imageView!.contentMode = .scaleAspectFit; button.contentHorizontalAlignment = .left