自己遇到的一些swift4的变化做一个记录,持续更新添加
字符串String
-
截取(原subString)
//swift 4
let from = String(cString[index...]) // let from = cString.substring(from: index)
let to = String(cString[..<n]) // let to = cString.substring(to: i)
let sub = String(cString[i..<j]) // let sub = cString.substring(with: i..<j)
-
一些属性,现在可以直接使用的
- 字符串长度
let count = string.count // let count = string.characters.count
第三方库
// 定义一个dataSource
// swift 4
let dataSource = RxTableViewSectionedReloadDataSource<SectionModel<String, Any>>(configureCell: {
(dataSource, tableView, indexPath, model) in
return UITableViewCell()
})
// swift 3
let dataSource = RxTableViewSectionedReloadDataSource<SectionModel<String, Any>>()
dataSource.configureCell = {
(dataSource, tableView, indexPath, model) in
return UITableViewCell()
})
// swift4
self.dataArray.asObservable()
.bind(to: self.tableView.rx.items(dataSource: dataSource))
.disposed(by: disposeBag)
// swift3
self.dataArray.asObservable()
.bind(to: self.tableView.rx.items(dataSource: dataSource))
.addDisposableTo(disposeBag)
网友评论