在Swift3转换中获取advancedBy错误
我正在将我的Swift2.3代码转换为Swift3,在使用advancedBy的行中出现错误。XCode向我展示了一个使用offsetBy的替换代码,但我还是不明白在Swift3转换中获取advancedBy错误,swift3,Swift3,我正在将我的Swift2.3代码转换为Swift3,在使用advancedBy的行中出现错误。XCode向我展示了一个使用offsetBy的替换代码,但我还是不明白 func unhideEmaimage(_ imageFile: String) { let dotLocation = imageFile.characters.index(of: ".") self.emaImage.texture = SKTexture(imageNamed: imageFile)
func unhideEmaimage(_ imageFile: String) {
let dotLocation = imageFile.characters.index(of: ".")
self.emaImage.texture = SKTexture(imageNamed: imageFile)
if dotLocation != nil {
let filenameInitial = imageFile.startIndex
let filenameLast = dotLocation!.advancedBy(-1)
let filenamePart:String = imageFile[filenameInitial...filenameLast]
}
下面是XCode向我展示如何修复错误的代码。但是,我仍然不知道如何修改
let filenameLast = "String.CharacterView corresponding to your index".index(dotLocation!, offsetBy: -1)
请告诉我修复此错误的方法。提前谢谢。您应该写以下内容:
let filenameLast = imageFile.index(dotLocation!,offsetBy: -1)
可能重复的