Expanding tilde in path == bad practice?

In Xcode 7 beta 6, the stringByExpandingTildeInPath method has been removed from NSString.

And There doesn't seem to be any way of expanding tilde in paths in NSURL either.


Should I take this as a hint that we should no longer deal with tilde expansion (and if we really have to, we should write our own custom code it)?

If so, what is the rationale?

Answered by Tia Lapis in 46476022

It is still there, but no longer a method. It's a read only property that return a expanded string.


var bla2 : NSString = "~/"
print (bla2.stringByExpandingTildeInPath)
Accepted Answer

It is still there, but no longer a method. It's a read only property that return a expanded string.


var bla2 : NSString = "~/"
print (bla2.stringByExpandingTildeInPath)

Ouch, hehe, thanks, I don't know how I could miss it. I guess I mixed up String and NSString when trying to find it.

Should I take this as a hint that we should no longer deal with tilde expansion […]?

That depends on your goals. As Tia Lapis said, you can continue down this road if you want to, but whether you should depends on what you’re actually doing with these paths. For example:

  • If you’re building a command line tool for OS X, it makes perfect sense to implement tilde expansion in situations where the shell doesn’t do that for you.

  • OTOH, an app would typically be better served by using a relative bookmark.

  • OTOOH, if you’re creating an app that’s specifically targeted at technical folks, tilde expansion may still be appropriate.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Expanding tilde in path == bad practice?
 
 
Q