diff --git a/CHANGELOG.md b/CHANGELOG.md index c4d56f3..97b683a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ they don't appear in plaintext within the source or binary of your app. [Tyler Milner](https://github.com/tylermilner) [#65](https://github.com/BottleRocketStudios/iOS-UtiliKit/pull/65) +* 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) + * Added Carthage support. [Ryan Gant](https://github.com/ganttastic) [#68](https://github.com/BottleRocketStudios/iOS-UtiliKit/pull/68) diff --git a/Sources/UtiliKit/General/URL+Extensions.swift b/Sources/UtiliKit/General/URL+Extensions.swift new file mode 100644 index 0000000..2818a94 --- /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. 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) { + 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 7b6584c..e45a0e2 100644 --- a/UtiliKit.xcodeproj/project.pbxproj +++ b/UtiliKit.xcodeproj/project.pbxproj @@ -77,6 +77,7 @@ 8698D0282061A3930065AE20 /* ViewControllerB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8698D0082061A3930065AE20 /* ViewControllerB.swift */; }; 8698D0292061A3930065AE20 /* WipeTransitionAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8698D0092061A3930065AE20 /* WipeTransitionAnimator.swift */; }; B4CCCAEF22D57284001A7A4F /* DefaultContainerTransitionAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8698CFA620619EAD0065AE20 /* DefaultContainerTransitionAnimator.swift */; }; + B4A5231A22E6925B00AB1424 /* URL+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4A5231922E6925B00AB1424 /* URL+Extensions.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -183,6 +184,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 */ @@ -355,6 +357,7 @@ children = ( 8698CFA820619EAD0065AE20 /* FileManager+Extensions.swift */, 8698CFA920619EAD0065AE20 /* UIView+Extensions.swift */, + B4A5231922E6925B00AB1424 /* URL+Extensions.swift */, ); path = General; sourceTree = ""; @@ -638,6 +641,7 @@ 8698CFC120619EAD0065AE20 /* NibLoadable.swift in Sources */, 8698CFBF20619EAD0065AE20 /* UIView+Extensions.swift in Sources */, 8698CFCA20619EAD0065AE20 /* VersionConfig.swift in Sources */, + B4A5231A22E6925B00AB1424 /* URL+Extensions.swift in Sources */, 8698CFC420619EAD0065AE20 /* UICollectionView+Extensions.swift in Sources */, 0EC8025C209CE9C90051F732 /* Configurable.swift in Sources */, 8698CFC820619EAD0065AE20 /* TimelessDate.swift in Sources */,