最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

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

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.179 seconds, using 22.09MB memory