appendingPathExtension(_:)
Returns a new string made by appending to the receiver an extension separator followed by a given extension.
Declaration
func appendingPathExtension(_ str: String) -> String?Parameters
- str:
The extension to append to the receiver.
Return Value
A new string made by appending to the receiver an extension separator followed by ext.
Discussion
The following table illustrates the effect of this method on a variety of different paths, assuming that ext is supplied as @"tiff":
Receiver’s String Value | Resulting String |
|---|---|
“ | “ |
“ | “ |
“ | “ |
“ | “ |
Note that adding an extension to @"/tmp/" causes the result to be @"/tmp.tiff" instead of @"/tmp/.tiff". This difference is because a file named @".tiff" is not considered to have an extension, so the string is appended to the last nonempty path component.
Note that this method only works with file paths (not, for example, string representations of URLs).
Special Considerations
Prior to OS X v10.9 this method did not allow you to append file extensions to filenames starting with the tilde character (~).
See Also
Working with Paths
path(withComponents:)pathComponentscompletePath(into:caseSensitive:matchesInto:filterTypes:)fileSystemRepresentationgetFileSystemRepresentation(_:maxLength:)isAbsolutePathlastPathComponentpathExtensionabbreviatingWithTildeInPathappendingPathComponent(_:)deletingLastPathComponentdeletingPathExtensionexpandingTildeInPathresolvingSymlinksInPathstandardizingPath