Swift: How to expand a tilde in a path String

前端 未结 4 1031
小蘑菇
小蘑菇 2021-02-20 04:22

How can I expand a path String with a tilde in Swift? I have a string like \"~/Desktop\" and I\'d like to use this path with the NSFileManager methods,

4条回答
  •  故里飘歌
    2021-02-20 04:42

    Swift 4 Extension

    public extension String {
    
        public var expandingTildeInPath: String {
            return NSString(string: self).expandingTildeInPath
        }
    
    }
    

提交回复
热议问题