From 3839378c5600523be2912c4239927ced5442b848 Mon Sep 17 00:00:00 2001 From: Will McGinty Date: Mon, 22 Jul 2019 20:01:53 -0500 Subject: [PATCH 1/4] Conform URL to ExpressibleByStringLiteral --- Sources/UtiliKit/General/URL+Extensions.swift | 23 +++++++++++++++++++ UtiliKit.xcodeproj/project.pbxproj | 4 ++++ 2 files changed, 27 insertions(+) create mode 100644 Sources/UtiliKit/General/URL+Extensions.swift diff --git a/Sources/UtiliKit/General/URL+Extensions.swift b/Sources/UtiliKit/General/URL+Extensions.swift new file mode 100644 index 0000000..742e76b --- /dev/null +++ b/Sources/UtiliKit/General/URL+Extensions.swift @@ -0,0 +1,23 @@ +// +// URL+Extensions.swift +// UtiliKit-iOS +// +// Created by William McGinty on 7/22/19. +// Copyright © 2019 Bottle Rocket Studios. All rights reserved. +// + +import Foundation + +extension URL: ExpressibleByStringLiteral { + + /// Creates a `URL` from a string literal object. This initializer will `fatalError` if given an invalid URL string. + /// + /// - Parameter value: The literal string to which a `URL` object should be initialized, or crash if invalid. + public init(stringLiteral value: StaticString) { + guard let url = URL(string: value.description) else { + fatalError("Invalid URL string: \(value)") + } + + self = url + } +} diff --git a/UtiliKit.xcodeproj/project.pbxproj b/UtiliKit.xcodeproj/project.pbxproj index ab4412f..f1d5914 100644 --- a/UtiliKit.xcodeproj/project.pbxproj +++ b/UtiliKit.xcodeproj/project.pbxproj @@ -71,6 +71,7 @@ 8698D0272061A3930065AE20 /* ViewControllerA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8698D0072061A3930065AE20 /* ViewControllerA.swift */; }; 8698D0282061A3930065AE20 /* ViewControllerB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8698D0082061A3930065AE20 /* ViewControllerB.swift */; }; 8698D0292061A3930065AE20 /* WipeTransitionAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8698D0092061A3930065AE20 /* WipeTransitionAnimator.swift */; }; + B4A5231A22E6925B00AB1424 /* URL+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4A5231922E6925B00AB1424 /* URL+Extensions.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -164,6 +165,7 @@ 8698D0072061A3930065AE20 /* ViewControllerA.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewControllerA.swift; sourceTree = ""; }; 8698D0082061A3930065AE20 /* ViewControllerB.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewControllerB.swift; sourceTree = ""; }; 8698D0092061A3930065AE20 /* WipeTransitionAnimator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WipeTransitionAnimator.swift; sourceTree = ""; }; + B4A5231922E6925B00AB1424 /* URL+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+Extensions.swift"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -302,6 +304,7 @@ children = ( 8698CFA820619EAD0065AE20 /* FileManager+Extensions.swift */, 8698CFA920619EAD0065AE20 /* UIView+Extensions.swift */, + B4A5231922E6925B00AB1424 /* URL+Extensions.swift */, ); path = General; sourceTree = ""; @@ -587,6 +590,7 @@ 8698CFBF20619EAD0065AE20 /* UIView+Extensions.swift in Sources */, 8698CFBB20619EAD0065AE20 /* ContainerViewController.swift in Sources */, 8698CFCA20619EAD0065AE20 /* VersionConfig.swift in Sources */, + B4A5231A22E6925B00AB1424 /* URL+Extensions.swift in Sources */, 8698CFC420619EAD0065AE20 /* UICollectionView+Extensions.swift in Sources */, 0E6E8C6D2112551200617815 /* ContainerViewController+ManagedChildren.swift in Sources */, 0EC8025C209CE9C90051F732 /* Configurable.swift in Sources */, From 7559ae1869e1198205222bde6f9d596176ddefe7 Mon Sep 17 00:00:00 2001 From: Will McGinty Date: Mon, 22 Jul 2019 20:03:31 -0500 Subject: [PATCH 2/4] Create a changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1446a6b..eb0375a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ [Tyler Milner](https://github.com/tylermilner) [#65](https://github.com/BottleRocketStudios/iOS-UtiliKit/pull/65) +* Conform URL to ExpressibleByStringLiteral +[Will McGinty](https://github.com/willmcginty) +[#66](https://github.com/BottleRocketStudios/iOS-UtiliKit/pull/66) + ##### Bug Fixes * None From d2805137c11dc247fde0683797579c52dac038fb Mon Sep 17 00:00:00 2001 From: Will McGinty Date: Tue, 23 Jul 2019 10:43:16 -0500 Subject: [PATCH 3/4] Add an example to changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb0375a..51407ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ [Tyler Milner](https://github.com/tylermilner) [#65](https://github.com/BottleRocketStudios/iOS-UtiliKit/pull/65) -* Conform URL to ExpressibleByStringLiteral +* Conform URL to ExpressibleByStringLiteral (e.g. `let url: URL = "www.apple.com"`) [Will McGinty](https://github.com/willmcginty) [#66](https://github.com/BottleRocketStudios/iOS-UtiliKit/pull/66) From 19d16b10e9ee1b7d657abb60f7089c1911fc805a Mon Sep 17 00:00:00 2001 From: Will McGinty Date: Tue, 23 Jul 2019 11:41:32 -0500 Subject: [PATCH 4/4] Add caution to documentation --- Sources/UtiliKit/General/URL+Extensions.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/UtiliKit/General/URL+Extensions.swift b/Sources/UtiliKit/General/URL+Extensions.swift index 742e76b..2818a94 100644 --- a/Sources/UtiliKit/General/URL+Extensions.swift +++ b/Sources/UtiliKit/General/URL+Extensions.swift @@ -10,7 +10,7 @@ import Foundation extension URL: ExpressibleByStringLiteral { - /// Creates a `URL` from a string literal object. This initializer will `fatalError` if given an invalid URL string. + /// Creates a `URL` from a string literal object. This initializer will `fatalError` if given an invalid URL string. This initializer is intended for pre-defined strings, and should be used with extreme caution. /// /// - Parameter value: The literal string to which a `URL` object should be initialized, or crash if invalid. public init(stringLiteral value: StaticString) {