Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve 'scanLocation' was deprecated in iOS 13.0

When trying to use a Scanner I am getting the warning that 'scanLocation' was deprecated in iOS 13.0. Since being able to scan from the next location is rather fundamental to scanning a String, wondering what to use instead of scanLocation. Apple's documentation for Scanner does not even mention the deprecation, let alone suggest what has taken the place of scanLocation.

Example of using scanLocation, which is deprecated:

while !scanner.isAtEnd {
    print(scanner.scanUpToCharacters(from: brackets))
    let block = scanner.string[scanner.currentIndex...]
    print(block)
    scanner.scanLocation = scanner.scanLocation + 1
}
like image 573
Chuck Krutsinger Avatar asked Nov 07 '19 17:11

Chuck Krutsinger


1 Answers

tl;dr - use currentIndex instead of scanLocation when using Scanner in Swift.

Shame on Apple for the poor documentation. But based on information in the NSScanner.h file for the Objective-C version of Scanner, only in Swift, the scanLocation property has been deprecated and replaced with the currentIndex property.

like image 183
rmaddy Avatar answered Sep 19 '22 13:09

rmaddy