Skip to content

Instantly share code, notes, and snippets.

View VaslD's full-sized avatar

Yi Ding VaslD

  • Shandong, China
View GitHub Profile
extension UIDevice {
func systemVersion() -> String {
let os = switch self.userInterfaceIdiom {
case .pad: "iPadOS"
case .mac: "Mac Catalyst"
case .tv: "tvOS"
case .vision: "visionOS"
default: "iOS"
}
let version = "\(os) \(self.systemVersion)"
import Foundation
/// 四字符码,也称四字代码、FCC、4CC,大量运用于文件格式和经典 Mac OS API 中。
///
/// Darwin 提供 `FourCharCode` 数据类型用于保存四字符码,但 `FourCharCode` 只是 32 位整数 (`UInt32`, `CUnsignedInt`)
/// 的类型别名。在编程中,四字符码通常以字符串(例如:`"avc1"`)而非整数(例如:`1635148593`)表示,因此
/// `FourCharCode` 难以使用;也由于 `FourCharCode` 并非独立类型,向其添加扩展将导致扩展方法在所有整数上可用,极易引起误解且污染
/// Swift 标准类型 API。
///
/// ``FourCC`` 声明了新的类型,提供对 `FourCharCode` 的封装。``FourCC`` 可在源代码中通过字符串构造、或在运行时通过 `FourCharCode`
#!/usr/bin/swift
import Foundation
import Security
let manager = FileManager.default
// Print usage if called with no arguments.
var inputs = CommandLine.arguments
if let command = inputs.first {
import Foundation
import Network
/// TCP 监听(服务端)
public final class TCPServer: Sendable {
let queue: DispatchQueue
let listener: NWListener
public init(port: Int) throws {
guard let unsigned = UInt16(exactly: port), let port = NWEndpoint.Port(rawValue: unsigned) else {
import Foundation
import Network
public typealias TCPClient = TCPConnection
/// TCP 节点(客户端)连接
///
/// 由于 TCP 是全双工通讯,服务端也需要作为节点建立连接。
public final class TCPConnection: Sendable {
let queue: DispatchQueue
import UIKit
open class UICollectionViewPlus: UICollectionView, UICollectionViewDelegate {
// MARK: Scroll
override public init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
super.init(frame: frame, collectionViewLayout: layout)
super.delegate = self
}
import UIKit
open class UITableViewPlus: UITableView, UITableViewDelegate {
// MARK: Scroll
override public init(frame: CGRect, style: UITableView.Style) {
super.init(frame: frame, style: style)
super.delegate = self
}
@VaslD
VaslD / AES-CBC.swift
Last active March 25, 2023 19:20
East-to-use AES-CBC in Swift, UnsafePointer & Data supported.
import CommonCrypto
import CryptoKit
import Foundation
// MARK: - AES.CBC
public extension AES {
enum CBC {}
}
@VaslD
VaslD / AA.swift
Created March 9, 2023 18:03
Apple Archive
import AppleArchive
import CryptoKit
import Foundation
import System
public enum AA {
public static let version = Int(APPLE_ARCHIVE_API_VERSION)
static let fields = ArchiveHeader.FieldKeySet("TYP,PAT,LNK,DEV,UID,GID,MOD,FLG,MTM,CTM,SH2,DAT,SIZ")!
import Foundation
import ArgumentParser
public enum Path {
static let path = ProcessInfo.processInfo.environment["PATH"]!.components(separatedBy: ":")
public static func find(_ command: String) throws -> URL {
let files = FileManager.default
for path in Self.path {
let executable = URL(fileURLWithPath: path).appendingPathComponent(command, isDirectory: false)