测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布时间最后发布日期 | 2017年9月 |
SwiftSwift 版本 | 3.0 |
SPM支持使用 SPM | ✓ |
由 Allan Bto 维护。
用于各种项目的框架分组工具
注意:此框架仅仅是工具的集合,以及一些“方便的”功能。
请随意选择适合您项目的功能和示例代码,而不是包含整个 pod。
Swiftility 通过 CocoaPods 提供。要安装,只需将以下行添加到您的 Podfile:
pod "Swiftility"
import Swiftility
查看我使用 Swiftility 编写的 MVVM 实现示例的 链接
轻量级 Swift 绑定
struct Dynamic<T> {
var value: T
// ...
init(_ value: T)
// ...
func bind(listener: T -> Void)
// ...
}
/// Usage example
var email: Dynamic<String>("")
email.bind { value in
print("Email is now: \(value)")
}
email.value = "[email protected]"
// prints "Email is now: [email protected]"
便捷使用 GCD 方法
async()
async {
// Asynchronous code
async_main {
// Main thread code
}
}
after()
after(2.5) {
// Executed after 2.5 seconds
}
once()
once("someToken") {
// Executed only once for the given token
}
debounce()
let debouncedFunction = debounced(0.5) { someVarOrVoid in
// Executed only every 0.5 seconds
}
debouncedFunction(someVarOrVoid)
/// Define Storyboard names
extension UIStoryboard.Name
{
static let settings = UIStoryboard.Name(name: "Settings")
}
/// Define your view controller built in the `Settings` storyboard
// "SettingsViewController" should be the identifier in the storyboard (same as class name)
class SettingsViewController: UIViewController, FromStoryboard
{
static let storyboardName: UIStoryboard.Name = .settings
}
/// Now you can do this
let settingsVC = SettingsViewController.instantiateFromStoryboard()
// "SettingsViewController.xib" should be the file containing SettingsViewController
class SettingsViewController: UIViewController, FromNib { ... }
// "MyView.xib" should be the file containing MyView
class MyView: UIView, FromNib { ... }
/// Now you can do this
let settingsVC = SettingsViewController.instantiateFromNib()
let myView = MyView.instantiateFromNib()
/// Define cell defined in "MyCell.xib"
class MyCell: UITableViewCell, FromNib { ... }
/// Register cell
tableView.register(MyCell.self)
/// Later
let cell = tableView.dequeueReusableCell() as MyCell
/// Define cell defined in "MyCell.xib"
class MyCell: UICollectionViewCell, FromNib { ... }
collectionView.register(MyCell.self)
/// Define custom view defined in "MyCustomView.xib"
class MyCustomView: UICollectionReusableView, FromNib { ... }
collectionView.register(MyCustomView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader)
/// Later
let supView: MyCustomView = collectioView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, for: someIndexPath)
let cell = collectioView.dequeueReusableCell(for: someIndexPath) as MyCell
参见 扩展页面
Allan Barbato,[email protected]
Swiftility可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。