Porting code to Linux: issue with Scanner


I am porting so Swift library code to Linux and I have issue with Scanner.scanUpTo.

It seems that some form of this method (without into: parameter) is available in Swift corelibs foundation: https://github.com/apple/swift-corelibs-foundation/blob/f5a076deb72b63896433d2dcd2af0d3b48ac2ae8/Foundation/Scanner.swift#L673

However, I am not sure how to leverage this and make the code multiplatform.
Importing Foundation on Linux is not enough to make it available.

Any tips ?

Thanks !

@Tony_Parker, is this a missing method in corelibs-foundation?

@millenomi is looking into this.

Indeed! Stay tuned.

1 Like


I am not yet sure why it is needed, but I could wrap the difference between ScanUpTo on MacOS and Linux as follow:

fileprivate extension Scanner {
    func scanUpToWrap(string: String) -> String? {
        #if canImport(Darwin)
        var result: NSString?
        guard scanUpTo(string, into: &result) != false else { return nil }
        return result as String?
        return scanUpToString(string)
Terms of Service

Privacy Policy

Cookie Policy