Skip to content

Instantly share code, notes, and snippets.

View liuzhida33's full-sized avatar

Holiday liuzhida33

  • Joylife
  • Beijing China
View GitHub Profile
@liuzhida33
liuzhida33 / CodableDefault.swift
Created September 8, 2022 08:47
Codable 添加默认值
protocol CodableDefaultSource {
associatedtype Value: Codable
static var defaultValue: Value { get }
}
enum CodableDefault {}
extension CodableDefault {
@propertyWrapper
@liuzhida33
liuzhida33 / Bundle+Fix.swift
Created September 7, 2022 07:25
访问Bundle资源
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.
@liuzhida33
liuzhida33 / PresentTransition.swift
Created September 5, 2022 07:45
适配Uniapp打开方式自定义弹出动画(包裹导航控制器)
/// Modal 转场动画
class PresentTransition: NSObject, UIViewControllerAnimatedTransitioning {
enum Transition {
case present
case dismiss
}
private var tran: Transition = .present
@liuzhida33
liuzhida33 / UIViewController+TopMostController.swift
Last active December 6, 2021 01:29
Get TopMostController of UIViewController
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? {
@liuzhida33
liuzhida33 / 20181202.md
Last active March 26, 2021 09:28
iOS 制作基于pod开发第三方framework的二次封装

iOS 制作基于pod开发第三方framework的二次封装

主要记录如何将第三方SDK的.a或framwwork集成到自己的framework中,并构建自己的pod发布到私有库所遇到的问题。

集成

  1. 打开第三方SDK找到二进制文件(以iflyMSC.framework为例)
  2. 将iflyMSC的二进制文件改成.a的后缀名,重命名为libiflyMSC.a。 如果不加lib前缀,那么在后面进行pod lib lint命令时有可能会遇到这样的错误提示:
@liuzhida33
liuzhida33 / Dispatch.swift
Created November 2, 2020 05:48
打印当前队列名
String(cString: __dispatch_queue_get_label(nil), encoding: .utf8)
private struct OrderTime: Sequence, IteratorProtocol {
struct DayHour {
let date: Date
let hours: [Date]
}
let minimumDate: Date
let maximumDate: Date
@liuzhida33
liuzhida33 / CacheManager.swift
Created October 19, 2020 01:00
计算iOS常见缓存大小及清除缓存
import RxCocoa
import RxSwift
import Kingfisher
import NSObject_Rx
import WebKit
/// 缓存管理
final class CacheManager: HasDisposeBag {
/// 缓存类型
@liuzhida33
liuzhida33 / JSON.swift
Created July 11, 2020 02:20
如何在Swift中轻松解析深度json
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)]
}
}
@liuzhida33
liuzhida33 / AVPlayer Background Design.md
Created July 8, 2020 01:48
AVPlayer Background Design

AVPlayer Background Design

  1. 使用NSNotification来监听进入后台和前台事件

    .UIApplicationWillEnterForeground .UIApplicationDidEnterBackground

  2. 长按home键不会响应 1. 中的两个通知事件,需要同时使用以下通知

    .UIApplicationWillResignActive .UIApplicationDidBecomeActive