下面是我的swift 2.0代码。我的代码在swift 3.1中看起来如何?swift 3迁移错误
let index: String.Index = advance(cell.itemPriceLabel.text!.startIndex, 3)
var trimmedPrice = productPrice.substring(from: index)
下面是我的swift 2.0代码。我的代码在swift 3.1中看起来如何?swift 3迁移错误
let index: String.Index = advance(cell.itemPriceLabel.text!.startIndex, 3)
var trimmedPrice = productPrice.substring(from: index)
最明显的变化是,指标不再有后继(), 前身(),advancedBy(:),advancedBy(:上限:),或distanceTo (_ :) 方法。相反,这些操作被移动到集合中,现在该集合负责递增和递减其索引。
myIndex.successor()=> myCollection.index(后:myIndex)
myIndex.predecessor()=> myCollection.index(前:myIndex)
myIndex.advance(按:...)=> MyCollection的。指数(myIndex,offsetBy:...)
比你的代码将
if let text = priceLabel.text {
let index = text.index(text.startIndex, offsetBy: 3)
}
的Swift3
版本的代码如下:
let index = priceLabel.text!.index(priceLabel.text!.startIndex,offsetBy: 3)
什么是你的问题? –
什么是swift中的代码3.1 –