-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from BottleRocketStudios/literalURL
Conform URL to ExpressibleByStringLiteral
- Loading branch information
Showing
3 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters