最新消息:20190529 VPS服务器已从腾讯云香港换为Vultr新加坡,主题仍用朋友推荐的大前端D8

[已解决]swift代码出错:advance is unavailable call the advancedBy(n) method on the index

iOS crifan 431浏览 0评论

代码:

        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

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
65 queries in 0.102 seconds, using 18.77MB memory