Skip to content

Commit

Permalink
Merge pull request #66 from BottleRocketStudios/literalURL
Browse files Browse the repository at this point in the history
Conform URL to ExpressibleByStringLiteral
  • Loading branch information
wmcginty committed Aug 28, 2019
2 parents a16ce85 + c5eae85 commit fe77956
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions Sources/UtiliKit/General/URL+Extensions.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
4 changes: 4 additions & 0 deletions UtiliKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -183,6 +184,7 @@
8698D0072061A3930065AE20 /* ViewControllerA.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewControllerA.swift; sourceTree = "<group>"; };
8698D0082061A3930065AE20 /* ViewControllerB.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewControllerB.swift; sourceTree = "<group>"; };
8698D0092061A3930065AE20 /* WipeTransitionAnimator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WipeTransitionAnimator.swift; sourceTree = "<group>"; };
B4A5231922E6925B00AB1424 /* URL+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+Extensions.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -355,6 +357,7 @@
children = (
8698CFA820619EAD0065AE20 /* FileManager+Extensions.swift */,
8698CFA920619EAD0065AE20 /* UIView+Extensions.swift */,
B4A5231922E6925B00AB1424 /* URL+Extensions.swift */,
);
path = General;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down

0 comments on commit fe77956

Please sign in to comment.