代码:
func decode(entity : String) -> Character? {
if entity.hasPrefix("&#x") || entity.hasPrefix("&#X"){
return decodeNumeric(entity.substringFromIndex(advance(entity.startIndex, 3)), base: 16)
} else if entity.hasPrefix("&#") {
return decodeNumeric(entity.substringFromIndex(advance(entity.startIndex, 2)), base: 10)
} else {
return HtmlCharacterEntitiesDict[entity]
}
}
出错:
/Users/crifan/dev/dev_root/daryun/JianDao/iOS-Client/JianDao/CrifanLib.swift:838:64: ‘advance’ is unavailable: call the ‘advancedBy(n)’ method on the index
改为:
func decode(entity : String) -> Character? {
if entity.hasPrefix("&#x") || entity.hasPrefix("&#X"){
//return decodeNumeric(entity.substringFromIndex(advance(entity.startIndex, 3)), base: 16)
return decodeNumeric(entity.substringFromIndex(entity.startIndex.advancedBy(3)), base: 16)
} else if entity.hasPrefix("&#") {
// return decodeNumeric(entity.substringFromIndex(advance(entity.startIndex, 2)), base: 10)
return decodeNumeric(entity.substringFromIndex(entity.startIndex.advancedBy(2)), base: 10)
} else {
return HtmlCharacterEntitiesDict[entity]
}
}
即可。
转载请注明:在路上 » [已解决]swift代码出错:advance is unavailable call the advancedBy(n) method on the index