Swift 从urlString中获取后缀

public extension String {
    /// 从url中获取后缀 例:.pdf
    var pathExtension: String {
        guard let url = URL(string: self) else { return "" }
        return url.pathExtension.isEmpty ? "" : ".\(url.pathExtension)"
    }
}

你可能感兴趣的:(Swift 从urlString中获取后缀)