SJSwiftExtensions
安装
SJSwiftExtensions可以通过CocoaPods获取。要安装它,只需在Podfile中添加以下行:
pod 'SJSwiftExtensions'
用法
布尔值
let boolValue = true
boolValue.toggle = false
let trueValue = true
let falseValue = false
trueValue.stringValue /// "true"
falseValue.stringValue /// "false"
集合
var array: [Int] = []
array.isNotEmpty /// false
array.append(2)
array.isNotEmpty /// true
字符串
let emptyString = ""
emptyString.isNotEmpty // false
let someString = "fooBar"
someString.isNotEmpty // true
UIColor
let turquoise = UIColor(colorWithHexValue: 0x2FD3C7)
turquoise.darker(by: 10.0) // darkens color by 10 percents
turquoise.lighter(by: 10.0) // lightens color by 10 percents
UIViewController
控制器标识符,可以用来通过ID从Storyboard加载ViewController
let viewController = SomeBasicViewController
viewController.identifier // "SomeBasicViewController"
UITableView
注册单元格标识符与单元格类名相同
tableView.register(CustomTableViewCell.self)
取消声明显式标识符来预取单元格
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tv.dequeueReusableCell(forIndexPath: indexPath) as CustomTableViewCell
return cell
}
UITableViewCell
let cell = CustomTableViewCell
cell.identifier // "CustomTableViewCell"
作者
许可
SJSwiftExtensions是MIT许可。有关更多信息,请参阅LICENSE文件。