Skip to content
This repository was archived by the owner on Feb 2, 2022. It is now read-only.

Conversation

@nharbo
Copy link
Contributor

@nharbo nharbo commented Jan 9, 2019

No description provided.

Copy link

@siemensikkema siemensikkema left a comment

Choose a reason for hiding this comment

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

Looks handy! I made some suggestions that are hopefully a bit helpful...

shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "NO">
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">

Choose a reason for hiding this comment

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

Are these changes by accident?

Copy link
Contributor

Choose a reason for hiding this comment

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

I showed him how to enable code coverage. One could argue if it should be part of the entire framework or just set up locally

- withName: The `String` representation of the name of the queryParameter you want to change the value of
- toValue: The `String` representation of the new value for the queryParameter
- returns: a new `URL` instance with the changed queryParameters or nil if the change failed
*/

Choose a reason for hiding this comment

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

tip: Xcode can help creating the doc section for a function. Editor > Structure > Add Documentation. Or Command Option /

It saves time and helps create a standardized format for docs.

- toValue: The `String` representation of the new value for the queryParameter
- returns: a new `URL` instance with the changed queryParameters or nil if the change failed
*/
public func changeQueryParamValue(for url: URL, withName: String, toValue: String) -> URL? {

Choose a reason for hiding this comment

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

you can change the internal names for parameters like this:

public func changeQueryParamValue(for url: URL, withName name: String, toValue value: String) -> URL?

In the function withName and toValue don't make as much sense.

Choose a reason for hiding this comment

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

Have you considered changing the semantics from "change if it's there" to "add or replace"?

Copy link
Contributor

Choose a reason for hiding this comment

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

why are you passing in the url parameter? You are already working on an URL right?

Here is an example from your test

let url = URL(string: "http://example.com?token=addtokenhere") 
let queryParamUrl = url.changeQueryParamValue(for: url, withName: "token", toValue: "usertoken")

I would expect that I could call it like so instead:

let queryParamUrl = url.changeQueryParamValue(for: "token", to: "usertoken")

if
var component = URLComponents(url: url, resolvingAgainstBaseURL: false),
var queryItems = component.queryItems,
var firstParam = component.queryItems?.filter({$0.name == withName}).first,

Choose a reason for hiding this comment

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

How about: let index = queryItems.firstIndex(where: {$0.name == withName}) and then var queryItem = queryItems[index]
That uses the just unwrapped queryItems and doesn't go through the whole list before returning only the first item and it traverses the array only once (instead of first finding the query item and then finding the index of that query item).

- toValue: The `String` representation of the new value for the queryParameter
- returns: a new `URL` instance with the changed queryParameters or nil if the change failed
*/
public func changeQueryParamValue(for url: URL, withName: String, toValue: String) -> URL? {
Copy link
Contributor

Choose a reason for hiding this comment

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

why are you passing in the url parameter? You are already working on an URL right?

Here is an example from your test

let url = URL(string: "http://example.com?token=addtokenhere") 
let queryParamUrl = url.changeQueryParamValue(for: url, withName: "token", toValue: "usertoken")

I would expect that I could call it like so instead:

let queryParamUrl = url.changeQueryParamValue(for: "token", to: "usertoken")

shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "NO">
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
Copy link
Contributor

Choose a reason for hiding this comment

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

I showed him how to enable code coverage. One could argue if it should be part of the entire framework or just set up locally

- returns: a new `URL` instance with the changed queryParameters or nil if the change failed
*/
public func changeQueryParamValue(for url: URL, withName: String, toValue: String) -> URL? {
var internalUrl = url
Copy link
Contributor

Choose a reason for hiding this comment

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

here you could just say var internalURL = self...you are adding this extension to the URL

*/
public func changeQueryParamValue(for url: URL, withName: String, toValue: String) -> URL? {
var internalUrl = url
if let _ = internalUrl.value(forParameter: withName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

how about checking against nil instead?

if internalUrl.value(forParameter: name) != nil {

Copy link

@siemensikkema siemensikkema left a comment

Choose a reason for hiding this comment

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

Looks good!

@nharbo nharbo requested a review from pbodsk January 18, 2019 10:14
Copy link
Contributor

@pbodsk pbodsk left a comment

Choose a reason for hiding this comment

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

Looks fine, nothing further

:shipit: 🚀

BobDeKort and others added 7 commits April 15, 2019 16:06
Added Table of contents
Added the source code to the README
Added missing usage examples
Added Description of functionality for each section
Testing approach for linking to section with emoji
Removing emojis from section headers because they break the linking in the table of contents
@pbodsk pbodsk merged commit e7299a1 into master May 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants