A new string that replaces the current home directory portion of the current path with a tilde (
- iOS 2.0+
- macOS 10.0+
- tvOS 9.0+
- watchOS 2.0+
A new string based on the current string object. If the new string specifies a file in the current home directory, the home directory portion of the path is replaced with a tilde (
~) character. If the string does not specify a file in the current home directory, this method returns a new string object whose path is unchanged from the path in the current string.
Note that this method only works with file paths. It does not work for string representations of URLs.
For sandboxed apps in macOS, the current home directory is not the same as the user’s home directory. For a sandboxed app, the home directory is the app’s home directory. So if you specified a path of
/file for a sandboxed app, the returned path would be unchanged from the original. However, if you specified the same path for an app not in a sandbox, this method would replace the
/Users/<current_user> portion of the path with a tilde.