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

Commit 1cd6200

Browse files
authored
Merge pull request #52 from nodes-ios/develop
Prepare for new release
2 parents 2308937 + 38e6961 commit 1cd6200

File tree

6 files changed

+76
-20
lines changed

6 files changed

+76
-20
lines changed

Codemine/Extensions/CGPoint+Utilities.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public extension CGPoint {
1616
If the actual point is close to the `point` from the parameter it will return true.
1717

1818
- Parameters:
19-
- point: The `CGPoint` that will be checked if it is close to the actual `CGPoint`.
20-
- tolerance: Defines what range is tolerated to be close to the other `point`.
19+
- point: The `CGPoint` that will be checked if it is close to the actual `CGPoint`.
20+
- tolerance: Defines what range is tolerated to be close to the other `point`.
2121

2222
- Returns: `Boolean` - if close to return true, else false.
2323
*/

Codemine/Extensions/NSURL+Utilities.swift

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ public extension URL {
3434
Adds height, width and mode paramters to an url. To be used when fetching an image from a CDN, for example.
3535
Choose the `size` and the `mode` for the image url to define how an image will be provided from the backend.
3636

37-
- Parameters:
38-
- size: Set `size` as `CGSize` to define the size of the image that will be provided.
39-
- mode: Select a mode from predefined `ImageUrlMode` to set up a mode and define how an image will be provided.
40-
- heightParameterName: the name of the height paramter. Default is 'h'
41-
- widthParameterName: the name of the width paramter. Default is 'h'
42-
- Returns: `URL` as a `NSURL`.
37+
- parameters:
38+
- size: Set `size` as `CGSize` to define the size of the image that will be provided.
39+
- mode: Select a mode from predefined `ImageUrlMode` to set up a mode and define how an image will be provided.
40+
- heightParameterName: the name of the height paramter. Default is 'h'
41+
- widthParameterName: the name of the width paramter. Default is 'h'
42+
- returns: `URL` as a `NSURL`.
4343
*/
4444
public func appendingAssetSize(_ size: CGSize, mode: ImageUrlMode = .default, heightParameterName : String = "h", widthParameterName : String = "w") -> URL? {
4545
guard var urlComponents = URLComponents(url: self, resolvingAgainstBaseURL: false) else { return nil }
@@ -55,10 +55,10 @@ public extension URL {
5555
}
5656

5757
/**
58-
Finds the first value for a URL parameter in a `URL`
59-
- Parameters:
58+
Finds the first value for a URL parameter in a `URL`
59+
- parameters:
6060
- name: the URL parameter to look for
61-
- Returns: the first value found for `name` or nil if no value was found
61+
- returns: the first value found for `name` or nil if no value was found
6262
*/
6363
public func value(forParameter name: String) -> String? {
6464
guard let urlComponents = URLComponents(url: self, resolvingAgainstBaseURL: true),
@@ -68,5 +68,22 @@ public extension URL {
6868
let items = queryItems.filter({ $0.name == name })
6969
return items.first?.value
7070
}
71-
71+
72+
/**
73+
Appends queryParameters to a `URL`
74+
- parameters:
75+
- queryParameters: a `String` : `String` dictionary containing the queryParameters to append
76+
- returns: a new `URL` instance with the appended queryParameters or nil if the appending failed
77+
*/
78+
public func append(queryParameters: [String: String]) -> URL? {
79+
guard var urlComponents = URLComponents(url: self, resolvingAgainstBaseURL: true) else {
80+
return nil
81+
}
82+
83+
let urlQueryItems = queryParameters.map{
84+
return URLQueryItem(name: $0, value: $1)
85+
}
86+
urlComponents.queryItems = urlQueryItems
87+
return urlComponents.url
88+
}
7289
}

Codemine/Extensions/UIImage+Utilities.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public extension UIImage {
1818
parameter `cornerRadius` for setting up the rounded corners.
1919

2020
- Parameters:
21-
- color: The background color.
22-
- size: The size of the image.
23-
- cornerRadius: The corner radius.
21+
- color: The background color.
22+
- size: The size of the image.
23+
- cornerRadius: The corner radius.
2424

2525
- Returns: A 'UIImage' with the specified color, size and corner radius.
2626
*/
@@ -59,8 +59,8 @@ public extension UIImage {
5959
The `UIImage` that is set with the parameter `icon` will be centered on `image`.
6060

6161
- Parameters:
62-
- icon: The embedded image that will be on top.
63-
- image: The background image.
62+
- icon: The embedded image that will be on top.
63+
- image: The background image.
6464
- Returns: The combined image as `UIImage`.
6565
*/
6666
public class func embed(icon: UIImage, inImage image: UIImage ) -> UIImage? {

Codemine/Extensions/UIView+Utilities.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public extension UIView {
2626
Rounded corners for a `UIView`.
2727

2828
- Parameters:
29-
- corners: Defines which corners should be rounded.
30-
- radius: Defines the radius of the round corners as a `CGFloat`.
29+
- corners: Defines which corners should be rounded.
30+
- radius: Defines the radius of the round corners as a `CGFloat`.
3131
*/
3232
public func roundViewCorners(_ corners:UIRectCorner, radius: CGFloat) {
3333
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))

CodemineTests/CodemineTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class CodemineTests: XCTestCase {
5252
func testRange() {
5353
let str = "Hello world!"
5454
let range = str.range(from: "e", toString: " w")
55-
XCTAssertTrue(range?.lowerBound == str.characters.index(str.startIndex, offsetBy: 1) && range?.upperBound == str.characters.index(str.startIndex, offsetBy: 7), "range = \(range)")
55+
XCTAssertTrue(range?.lowerBound == str.index(str.startIndex, offsetBy: 1) && range?.upperBound == str.index(str.startIndex, offsetBy: 7), "range = \(range)")
5656
XCTAssertNil(str.range(from: "a", toString: "e"))
5757
XCTAssertNil(str.range(from: "e", toString: "b"))
5858

CodemineTests/URLParameterTests.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,45 @@ class URLParameterTests: XCTestCase {
5757
return
5858
}
5959
XCTAssertNil(urlWithNoParameters.value(forParameter: "nothere"))
60+
61+
}
62+
63+
func testCanReturnValueFromURLWithTwoParametersWithTheSameName() {
64+
guard let urlWithTwoParametersWithSameName = URL(string: "https://example.com?param1=value1&param2=value2&param1=value3") else {
65+
XCTFail("could not create URL")
66+
return
67+
}
68+
69+
let expectedValue = "value1"
70+
guard let actualValue = urlWithTwoParametersWithSameName.value(forParameter: "param1") else {
71+
XCTFail("no value found for parameter")
72+
return
73+
}
74+
XCTAssertTrue(expectedValue == actualValue)
75+
}
76+
77+
func testCanAppendQueryParameters() {
78+
guard let url = URL(string: "https://example.com") else {
79+
XCTFail("could not create URL")
80+
return
81+
}
82+
83+
let expectedValue1 = "value1"
84+
let expectedValue2 = "value2"
85+
86+
guard let queryParamUrl = url.append(queryParameters: ["param1" : expectedValue1, "param2" : expectedValue2]) else {
87+
XCTFail("could not create queryParamUrl")
88+
return
89+
}
90+
91+
//Are they even there?
92+
XCTAssertNotNil(queryParamUrl.value(forParameter: "param1"))
93+
XCTAssertNotNil(queryParamUrl.value(forParameter: "param2"))
94+
95+
//They were, but do they match then?
96+
XCTAssertTrue(queryParamUrl.value(forParameter: "param1")! == expectedValue1)
97+
XCTAssertTrue(queryParamUrl.value(forParameter: "param2")! == expectedValue2)
98+
6099
}
61100

62101
}

0 commit comments

Comments
 (0)