Dynamic Members

This commit is contained in:
Max Howell
2019-01-22 14:05:33 -05:00
parent 44be1c45a9
commit 859164e59f
5 changed files with 41 additions and 5 deletions

View File

@@ -23,6 +23,8 @@ import Foundation
- Note: There may not be an actual filesystem entry at the path. The underlying
representation for `Path` is `String`.
*/
@dynamicMemberLookup
public struct Path: Equatable, Hashable, Comparable {
init(string: String) {
@@ -45,6 +47,12 @@ public struct Path: Equatable, Hashable, Comparable {
return URL(fileURLWithPath: string)
}
/// Facilitates constructing paths for static strings
public subscript(dynamicMember pathComponent: String) -> Path {
let str = (string as NSString).appendingPathComponent(pathComponent)
return Path(string: str)
}
/**
Returns the parent directory for this path.