美文网首页
swift 4.0 自己遇到的一些变化

swift 4.0 自己遇到的一些变化

作者: StoneWing | 来源:发表于2017-11-02 16:53 被阅读46次

自己遇到的一些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)

相关文章

网友评论

      本文标题:swift 4.0 自己遇到的一些变化

      本文链接:https://www.haomeiwen.com/subject/soqapxtx.html