HotCocoa
HotCocoa 是一组扩展,为 Cocoa 和 Cocoa Touch 提供额外的功能和语法糖。
示例
UIColor & NSColor
使用0到255的rgb值构建一个 UIColor
或 NSColor
let color = UIColor(r: 5, g: 185, b: 255)
或者
let color = NSColor(r: 5, g: 185, b: 255)
使用十六进制数字构建一个 UIColor
let color = UIColor(hex: 0x02B8FF)
或者十六进制字符串
let color = UIColor(hexString: "02B8FF")
UIWindow
使用给定的 UIViewController
创建并显示一个新 UIWindow
let window = UIWindow(rootViewController: ViewController()) // UIScreen.main.bounds is the default frame
或者
let window = UIWindow(frame: myRect, rootViewController: ViewController())
UIViewController
用户在屏幕上点击时轻松隐藏键盘
viewController.hideKeyboardWhenTappedAround()
在 UIViewController
中轻松显示 UIAlertController
var actions = [UIAlertActions]()
...
viewController.displayAlertController(title: "Important", message: "This is an alert!", actions: actions) // A completion closure can be added if necessary
UserDefaults
轻松将符合 Codable 协议的任何值保存到 UserDefaults
struct MyStruct: Codable { ... }
let myStruct = MyStruct()
UserDefaults.standard.set(object: myStruct, forKey: "myStruct")
并且同样轻松地恢复它
myStruct = UserDefaults.get(type: MyStruct, forKey: "myStruct")
还有更多功能!
将其用于项目以查看可用的功能。
安装
要求
- iOS 8.0+
- macOS 10.10+
- tvOS 9.0+
- Swift 4
CocoaPods
通过 CocoaPods 可以获取 HotCocoa。要安装它,请在 Podfile 中添加以下行
pod 'HotCocoa', '~> 1.0.0'
贡献
打开一个问题或提交一个 pull request。