最新消息:20210917 已从crifan.com换到crifan.org

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

iOS crifan 1298浏览 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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
94 queries in 0.195 seconds, using 23.31MB memory