Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Migrate to Swift 5 - #232

Merged
mindgraffiti merged 19 commits into
developfrom
issue/79-migrate-swift-5
Mar 13, 2020
Merged

Migrate to Swift 5#232
mindgraffiti merged 19 commits into
developfrom
issue/79-migrate-swift-5

Conversation

@mindgraffiti

@mindgraffiti mindgraffiti commented Mar 12, 2020

Copy link
Copy Markdown
Contributor

Description

Fixes #79
Fixes #149

Test this PR by checking out wordpress-mobile/WordPress-iOS#13641

In this PR:

  • updates shared pod schemes to 11.3
  • pod update to get the latest acceptable changes for the internal (WordPress) pods
  • update the dependent framework OHHTTPStubs from 6.1.0 -> 9.0
  • remove OH class prefix from code that uses OHHTTPStubs
  • update unit test target to use Swift 5
  • update main project to use Swift 5
  • enable base internationalization
  • update podspec to require Swift version 5
  • add a bug fix to logged info

Known issues

A warning will still remain in this project. Alamofire needs migrated from 4.x to 5.x in order to fully adopt Swift 5 in the project. A github issue will be filed for this.

Testing Details

  • bundle exec pod install

  • build and run the project

  • Please check here if your pull request includes additional test coverage.

@diegoreymendez diegoreymendez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mindgraffiti ! I did a first pass on this PR and added some comments with recommended changes.

Please let me know if there's anything else.

Comment thread WordPressKit/PluginDirectoryEntry.swift Outdated
rating = try container.decode(Int.self, forKey: .rating)

let icons = try? container.decodeIfPresent([String: String].self, forKey: .icons)
let icons = ((try? container.decodeIfPresent([String: String].self, forKey: .icons)) as [String : String]??)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these two lines should be:

let icons = try? container.decodeIfPresent([String: String].self, forKey: .icons)
icon = icons?["2x"].flatMap(URL.init(string:))

Comment thread WordPressKit/PluginDirectoryEntry.swift Outdated
let banners = try? container.nestedContainer(keyedBy: BannersKeys.self, forKey: .banners)

if let highRes = try? banners?.decodeIfPresent(String.self, forKey: .high) {
if let highRes = ((try? banners?.decodeIfPresent(String.self, forKey: .high)) as String??) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this whole block should be:

if let highRes = try? banners?.decodeIfPresent(String.self, forKey: .high) {
    banner = URL(string: highRes)
} else if let lowRes = try? banners?.decodeIfPresent(String.self, forKey: .low) {
    banner = URL(string: lowRes)
} else {
    banner = nil
}

Comment thread WordPressKit/WordPressComOAuthClient.swift
let responseString = String(data: data, encoding: String.Encoding.utf8),
let parser = WordPressRSDParser(xmlString: responseString),
let endpoint = (try? parser.parsedEndpoint()),
let endpoint = (((try? parser.parsedEndpoint()) as String??)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line should be:

let xmlrpc = try? parser.parsedEndpoint(),

And the immediate next line should be deleted. This one:

let xmlrpc = endpoint,

Comment thread WordPressKit/PluginDirectoryEntry.swift Outdated
rating = try container.decode(Int.self, forKey: .rating)

let icons = try? container.decodeIfPresent([String: String].self, forKey: .icons)
let icons = ((try? container.decodeIfPresent([String: String].self, forKey: .icons)) as [String : String]??)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a specific reason for casting to [String: String]? ? decodeIfPresent should return a [String: String] value or nil, depending if that value exists (and is not nil) or not, so if we leave this statement unchanged, can the following just be
icon = icons?["2x"].flatMap(URL.init(string:))?

or we could also:

if let icons = try container.decodeIfPresent([String: String].self, forKey: .icons) { icon = icons["2x"].flatMap(URL.init(string:)) }

@mindgraffiti mindgraffiti Mar 13, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a specific reason for casting to

No there is not. I let Xcode do the migrating and overlooked how odd that change really was. Correcting it now :)

Comment thread WordPressKit/PluginDirectoryEntry.swift Outdated
let banners = try? container.nestedContainer(keyedBy: BannersKeys.self, forKey: .banners)

if let highRes = try? banners?.decodeIfPresent(String.self, forKey: .high) {
if let highRes = ((try? banners?.decodeIfPresent(String.self, forKey: .high)) as String??) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could do:
if let highRes = try banners?.decodeIfPresent(String.self, forKey: .high) { banner = URL(string: highRes) }

let endpoint = (((try? parser.parsedEndpoint()) as String??)),
let xmlrpc = endpoint,
let xmlrpcURL = URL(string: xmlrpc)
else {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the whole guard statement can be simplified like so?

guard let data = data,
let responseString = String(data: data, encoding: String.Encoding.utf8),
let parser = WordPressRSDParser(xmlString: responseString),
let xmlrpc = try? parser.parsedEndpoint(),
let xmlrpcURL = URL(string: xmlrpc)
else {
failure(WordPressOrgXMLRPCValidatorError.invalid as NSError)
return
}

@mindgraffiti

Copy link
Copy Markdown
Contributor Author

@Gio2018 @diegoreymendez ready for a second review! I see what the icon property was attempting to. Please check the re-written code. This pod can be tested against this WPiOS branch: wordpress-mobile/WordPress-iOS#13641. You may have to bundle exec pod update WordPressKit to force the pod to update with the latest code in this branch.

To test the changed icon code, open PluginDirectoryEntry.swift in WPiOS and add a breakpoint to L87-L88. Then navigate to the "Plugins" page from your preferred site.

@mindgraffiti
mindgraffiti merged commit d6ab34f into develop Mar 13, 2020
@mindgraffiti
mindgraffiti deleted the issue/79-migrate-swift-5 branch March 13, 2020 20:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Logging of Social Login exposes OAuth Bearer token to log files Modify WordPressKit for Swift 5 support

3 participants