Reputation: 1358
I need to validate medicare number and I'm following this thread: How do I validate an Australian Medicare number?
I'm getting error as
Code is : String.Index does not have a member named advancedBy
let matches = expression.matchesInString(medicareNumber, options: NSMatchingOptions.ReportProgress, range: NSMakeRange(0, length))
if (matches.count > 0 && matches[0].numberOfRanges > 2) {
let base = medicareNumber.substringWithRange(medicareNumber.startIndex...medicareNumber.startIndex.advancedBy(matches[0].rangeAtIndex(1).length))
let checkDigitStartIndex = medicareNumber.startIndex.advancedBy(matches[0].rangeAtIndex(2).location )
let checkDigitEndIndex = checkDigitStartIndex.advancedBy(matches[0].rangeAtIndex(2).length)
let checkDigit = medicareNumber.substringWithRange(checkDigitStartIndex..<checkDigitEndIndex)
var total = 0
for i in 0..<multipliers.count {
total += Int(base.charAtIndex(i))! * multipliers[i]
}
return (total % 10) == Int(checkDigit)
}
I'm using Xcode 6.2 and how can I solve this issue? Please note I need to solve this without upgrade Xcode this moment.
Upvotes: 1
Views: 2610
Reputation: 48514
Use advance
let base = medicareNumber.substringWithRange(
medicareNumber.startIndex...advance(
medicareNumber.startIndex,
matches[0].rangeAtIndex(1).length
)
)
advance
has been deprecated in Swift2.
Use advanceBy
let base = medicareNumber.substringWithRange(
medicareNumber.startIndex...medicareNumber.startIndex.advancedBy(
matches[0].rangeAtIndex(1).length
)
)
advancedBy(_:)
has been deprecated in Swift3.
Use index(_:offsetBy:)
let base = medicareNumber.substringWithRange(
medicareNumber.startIndex...medicareNumber.index(
medicareNumber.startIndex,
offsetBy: matches[0].rangeAtIndex(1).length)
)
)
Upvotes: 1