Skip to content

Commit

Permalink
1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
EyreFree committed Mar 27, 2023
1 parent 0e5a4d2 commit 1557c93
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion EFFoundation.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'EFFoundation'
s.version = '1.5.4'
s.version = '1.6.0'
s.summary = 'EFFoundation.'

s.description = <<-DESC
Expand Down
2 changes: 1 addition & 1 deletion EFFoundation/Core/EFFoundation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
import UIKit

public func hideKeyboard() {
UIApplication.shared?.keyWindow?.endEditing(true)
UIApplication.shared()?.keyWindow()?.endEditing(true)
}
#endif
#endif
Expand Down
4 changes: 2 additions & 2 deletions EFFoundation/Core/Extension/CGFloat+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public extension CGFloat {
static let screenWidth: CGFloat = UIScreen.main.bounds.size.width
static let screenHeight: CGFloat = UIScreen.main.bounds.size.height
static let screenMinEdge: CGFloat = Swift.min(screenWidth, screenHeight)
static let topSafeAreaHeight: CGFloat = UIApplication.shared()?.keyWindow()?.safeAreaInsets.top ?? 0
static let bottomSafeAreaHeight: CGFloat = UIApplication.shared()?.keyWindow()?.safeAreaInsets.bottom ?? 0
#endif

static let navigationBarHeight: CGFloat = 44

var nsNumber: NSNumber {
return NSNumber(value: self)
Expand Down
4 changes: 2 additions & 2 deletions EFFoundation/Core/Extension/Date+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public extension Date {
func string(dateFormat: String = "yyyy-MM-dd HH:mm", timeZone: TimeZone = NSTimeZone.local, locale: Locale = Locale.current) -> String {
let dateFormatter: DateFormatter = DateFormatter()
dateFormatter.dateFormat = dateFormat
dateFormatter.timeZone = NSTimeZone.local
dateFormatter.locale = Locale.current
dateFormatter.timeZone = timeZone
dateFormatter.locale = locale
return dateFormatter.string(from: self)
}

Expand Down
6 changes: 3 additions & 3 deletions EFFoundation/Core/Extension/UIApplication+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ public extension UIApplication {
return isAppExtension
}()

static let shared: UIApplication? = {
static func shared() -> UIApplication? {
if isAppExtension {
return nil
}
let selector = NSSelectorFromString("sharedApplication")
guard UIApplication.responds(to: selector) else { return nil }
return UIApplication.perform(selector).takeUnretainedValue() as? UIApplication
}()
}

func keyWindow() -> UIWindow? {
guard let currentApplication = UIApplication.shared else { return nil }
let currentApplication = self
var targetWindow = currentApplication.keyWindow
if #available(iOS 13.0, tvOS 13.0, *) {
let scenes = currentApplication.connectedScenes.filter({ $0.activationState == .foregroundActive })
Expand Down
6 changes: 3 additions & 3 deletions EFFoundation/Core/Extension/UIFont+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ public extension UIFont {
}

static func pingFangSCUltralight(ofSize: CGFloat) -> UIFont {
return UIFont.init(name: "PingFangSC-Ultralight", size: ofSize) ?? UIFont.pingFangSCThin(ofSize: ofSize)
return UIFont.init(name: "PingFangSC-Ultralight", size: ofSize) ?? UIFont.pingFangSCRegular(ofSize: ofSize)
}

static func pingFangSCLight(ofSize: CGFloat) -> UIFont {
return UIFont.init(name: "PingFangSC-Light", size: ofSize) ?? UIFont.pingFangSCRegular(ofSize: ofSize)
return UIFont.init(name: "PingFangSC-Light", size: ofSize) ?? UIFont.pingFangSCUltralight(ofSize: ofSize)
}

static func pingFangSCThin(ofSize: CGFloat) -> UIFont {
return UIFont.init(name: "PingFangSC-Thin", size: ofSize) ?? UIFont.pingFangSCLight(ofSize: ofSize)
}

static func pingFangSCMedium(ofSize: CGFloat) -> UIFont {
return UIFont.init(name: "PingFangSC-Medium", size: ofSize) ?? UIFont.pingFangSCRegular(ofSize: ofSize)
return UIFont.init(name: "PingFangSC-Medium", size: ofSize) ?? UIFont.pingFangSCThin(ofSize: ofSize)
}

static func pingFangSCSemibold(ofSize: CGFloat) -> UIFont {
Expand Down
18 changes: 12 additions & 6 deletions EFFoundation/Core/Extension/UIViewController+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ import UIKit

public extension UIViewController {

var topViewController: UIViewController {
return presentedViewController?.topViewController
static var rootViewController: UIViewController? {
return UIApplication.shared()?.keyWindow()?.rootViewController
}

static var topViewController: UIViewController? {
return UIApplication.shared()?.keyWindow()?.rootViewController?.topViewController
}

private var topViewController: UIViewController {
return self.presentedViewController?.topViewController
?? (self as? UITabBarController)?.selectedViewController?.topViewController
?? (self as? UINavigationController)?.visibleViewController?.topViewController
?? self
}

static var topViewController: UIViewController {
return UIApplication.shared?.delegate?.window??.rootViewController?.topViewController ?? UIViewController()
}

func goBack(animated: Bool, completion: (() -> Void)? = nil) {
if let navigationController = self.navigationController, navigationController.viewControllers.count > 1 {
navigationController.popViewController(animated: animated) { [weak self] in
Expand All @@ -29,6 +33,8 @@ public extension UIViewController {
}
} else if nil != self.presentingViewController {
self.dismiss(animated: animated, completion: completion)
} else {
printLog("No need to goBack.")
}
}
}
Expand Down

0 comments on commit 1557c93

Please sign in to comment.