-
使用NSNotification来监听进入后台和前台事件
.UIApplicationWillEnterForeground
.UIApplicationDidEnterBackground
-
长按home键不会响应
1.
中的两个通知事件,需要同时使用以下通知.UIApplicationWillResignActive
.UIApplicationDidBecomeActive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol CodableDefaultSource { | |
associatedtype Value: Codable | |
static var defaultValue: Value { get } | |
} | |
enum CodableDefault {} | |
extension CodableDefault { | |
@propertyWrapper |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public let localBundle = Bundle.fixedModule | |
private final class CurrentBundleFinder {} | |
private let bundleNameIOS = "Backend_Backend" | |
private let bundleNameTests = "Backend_BackendTests" | |
extension Foundation.Bundle { | |
/// Returns the resource bundle associated with the current Swift module. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Modal 转场动画 | |
class PresentTransition: NSObject, UIViewControllerAnimatedTransitioning { | |
enum Transition { | |
case present | |
case dismiss | |
} | |
private var tran: Transition = .present | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIViewController { | |
static var rootViewController: UIViewController? { | |
guard let keyWindow = UIApplication.shared.delegate?.window ?? UIApplication.shared.windows.first(where: { $0.isKeyWindow && $0.rootViewController != nil }) else { return nil } | |
return keyWindow.rootViewController | |
} | |
static var topMostController: UIViewController? { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String(cString: __dispatch_queue_get_label(nil), encoding: .utf8) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private struct OrderTime: Sequence, IteratorProtocol { | |
struct DayHour { | |
let date: Date | |
let hours: [Date] | |
} | |
let minimumDate: Date | |
let maximumDate: Date | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RxCocoa | |
import RxSwift | |
import Kingfisher | |
import NSObject_Rx | |
import WebKit | |
/// 缓存管理 | |
final class CacheManager: HasDisposeBag { | |
/// 缓存类型 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func resolve<T>(_ jsonDictionary: [String: Any], keyPath: String) -> T? { | |
var current: Any? = jsonDictionary | |
keyPath.split(separator: ".").forEach { component in | |
if let maybeInt = Int(component), let array = current as? Array<Any> { | |
current = array[maybeInt] | |
} else if let dictionary = current as? JSONDictionary { | |
current = dictionary[String(component)] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct AnyAnimal: Animal { | |
let name: String | |
private let walker: () -> Void | |
private let eater: (Any) -> Void | |
init<T: Animal>(_ animal: T) { | |
name = animal.name | |
walker = { |
NewerOlder