Skip to content

Instantly share code, notes, and snippets.

View VaslD's full-sized avatar

Yi Ding VaslD

  • Shandong, China
View GitHub Profile
import Foundation
/// 四字符码,也称四字代码、FCC、4CC,大量运用于文件格式和经典 Mac OS API 中。
///
/// Darwin 提供 `FourCharCode` 数据类型用于保存四字符码,但 `FourCharCode` 只是 32 位整数 (`UInt32`, `CUnsignedInt`)
/// 的类型别名。在编程中,四字符码通常以字符串(例如:`"avc1"`)而非整数(例如:`1635148593`)表示,因此
/// `FourCharCode` 难以使用;也由于 `FourCharCode` 并非独立类型,向其添加扩展将导致扩展方法在所有整数上可用,极易引起误解且污染
/// Swift 标准类型 API。
///
/// ``FourCC`` 声明了新的类型,提供对 `FourCharCode` 的封装。``FourCC`` 可在源代码中通过字符串构造、或在运行时通过 `FourCharCode`
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)"