ViaSwiftUtils
《ViaSwiftUtils》能为您做些什么?以下是我们整理的一些示例
每次本地化字符串时都拼写NSLocalizedString
会很烦吗?
title = "HomePage.title".localized
print(title) // 'Main', '頭版', 'صفحه نخست', 'Startseite'
想要找到字符串中最长的单词?
print(germanText.longestWord())
// 'Verkehrsinfrastrukturfinanzierungsgesellschaft'
需要一个打乱(或任何其他MutableCollection
)的数组? [^3]
var numbers = [1, 2, 3, 4, 5, 6]
numbers.shuffleInPlace() //e.g. [4, 1, 5, 2, 6, 3]
想要获取Sequence
中具有Hashable
元素的唯一条目?
let emojis = ["😀", "👀", "😱", "😡", "👀", "😀", "👀", "😱"]
let uniqueEmojis = emojis.unique() // ["😀", "👀", "😱", "😡"]
处理TimeInterval
不方便吗?
let twelveDays = 12 * TimeInterval.day
let minutes = twelveDays / TimeInterval.minute // 17280
需要从现有图像创建一个圆角图像?
您的应用程序中的一个视图需要旋转吗?
someView.startRotating()
// ...
someView.stopRotating()
还有更多日期辅助方法和变量
let components = DateComponents(calendar: gregorian, era: 0,
year: 44, month: 3, day: 15, hour: 13)
let idesOfMarch = gregorian.date(from: components)!
let weekDay = idesOfMarch.dayOfWeek // 6
let daysSince = idesOfMarch.days(to: Date()) // 752533
这些只是几个例子。我们在持续扩展库,并接受Pull-Requests
要求
支持版本
Swift | Xcode | ViaSwiftUtils |
---|---|---|
4.2 - 5.0 | 10.X | 2.1.0 |
4.0 | 10.X | 2.0.5 |
3.2 - 4.1 | 9.X | 2.0.5 |
ViaSwiftUtils
如何安装通过 Cocoapods
在您的 Podfile
中添加以下行。请记住您需要启用 use_frameworks!
。
pod 'ViaSwiftUtils', '2.1.0'
通过 Carthage
在您的 Cartfile
中添加以下行
github "ViacomInc/ViaSwiftUtils" == 2.1.0
通过 Swift 包管理器
将以下内容添加到您的 Package.swift
dependencies: [
.package(url: "https://github.com/ViacomInc/ViaSwiftUtils.git", .exact("2.1.0")),
]
.target(name: <#yourTarget#>, dependencies: ["ViaSwiftUtils"]),
需要注意的是,只有 Foundation
中的部分函数在通过 SPM 使用时有效,因为 UIKit
在 Linux 或 MacOS 上不可用。
导入
使用上述三种方法之一安装框架后,在您的 .swift
文件中导入它。
import ViaSwiftUtils
许可证
遵守 Apache License 2.0 版本(“许可证”);除遵守许可证外,您不得使用此文件。您可以在以下位置获取许可证副本:
https://apache.ac.cn/licenses/LICENSE-2.0
除非适用的法律要求或书面同意,否则在许可证下分发的软件是以“现状”为基础分发的,不提供任何形式的保证或条件,无论是明示的还是暗示的。请参阅许可证以了解具体的管理权限和限制。