Last active
December 30, 2015 21:31
-
-
Save kristopherjohnson/46eda25ede3ec9b31e0c to your computer and use it in GitHub Desktop.
Swift String extension for generating filesystem paths from components
This file contains hidden or 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
| import Foundation | |
| extension String { | |
| /// Returns a new string made by appending to the receiver a filesystem path component. | |
| /// | |
| /// - parameter pathComponent: The path component to be appended to the receiver. | |
| /// | |
| /// - returns: A new `String` made by appending `pathComponent` to the receiver, preceded if necessary by a path separator. | |
| @warn_unused_result | |
| public func stringByAppendingPathComponent(pathComponent: String) -> String { | |
| return (self as NSString).stringByAppendingPathComponent(pathComponent) | |
| } | |
| /// Return a filesystem path composed of the specified components. | |
| /// | |
| /// - parameter pathComponents: list of filesystem path components. | |
| /// | |
| /// - returns: A `String` consisting of path components with delimiters between them. | |
| public static func fromPathComponents(pathComponents: String...) -> String { | |
| return pathComponents.reduce("", combine: { $0.stringByAppendingPathComponent($1) }) | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example use: