Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'advancedBy' API in Swift 2.0 [duplicate]

'advance' API has been removed in Swift 2.0.

If we use 'advance' API in Swift 2.0, it is throwing error saying 'advance' is unavailable: call the '**advancedBy(n)**' method on the index.

How to get index using advancedBy API in Swift 2.0?

Below is my scenario:

let startIndex = advance(cardNumber.endIndex, -4) 
let lastFourDigitsOfPhoneNumber = phoneNumber.substringFromIndex(startIndex)
like image 702
Coder Avatar asked Aug 26 '15 21:08

Coder


1 Answers

You need to call advancedBy on endIndex.

let startIndex = cardNumber.endIndex.advancedBy(-4)
let lastFourDigitsOfPhoneNumber = phoneNumber.substringFromIndex(startIndex)
like image 93
Tomáš Linhart Avatar answered Oct 15 '22 04:10

Tomáš Linhart