Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for watchOS 5 #318

Open
flaw600 opened this issue Aug 16, 2020 · 0 comments
Open

Add support for watchOS 5 #318

flaw600 opened this issue Aug 16, 2020 · 0 comments

Comments

@flaw600
Copy link

flaw600 commented Aug 16, 2020

Currently, the String extension requires watchOS 6 to build. For iPhone devices that cannot upgrade to iOS 13, this means that watchOS remains stuck at v5. This requires a complicated setup where a watchOS app has to manually defer to the iPhone via WKSession in order to use Swifter which leads to a more bloated codebase than would otherwise be required for a watchOS app MVP

Offending API usage (restricted to watchOS 6+):

   var queryStringParameters: Dictionary<String, String> {
        var parameters = Dictionary<String, String>()

        let scanner = Scanner(string: self)

        var key: String?
        var value: String?

        while !scanner.isAtEnd {
            key = scanner.scanUpToString("=") //this method is restricted to watchOS 6+
            _ = scanner.scanString(string: "=")

            value = scanner.scanUpToString("&")
            _ = scanner.scanString(string: "&")

            if let key = key, let value = value {
                parameters.updateValue(value, forKey: key)
            }
        }
        
        return parameters
    }

As currently written, the scanUpToString extension in Scanner++.swift does not support watchOS. As a result, dynamic linking tries to use the version from Foundation which requires watchOS 6. For devices that cannot upgrade to watchOS 6, this requires invoking WKSession to manually communicate between iOS & watchOS, which is not ideal

flaw600 added a commit to flaw600/Swifter that referenced this issue Aug 16, 2020
- Resolves an issue where when calling directly from watchOS 6, Dynamic Runtime may choose to opt to not use the extension version from String / Scanner (NSString and NSScanner as well) and provide an unexpected response
- Backports Swift 5 Foundation support to watchOS 5 for String++ and Scanner++
- Updated Swifter.podspec and Package.swift to support watchOS 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant