Instance Method

stringByAppendingPathExtension:

Returns a new string made by appending to the receiver an extension separator followed by a given extension.

Declaration

- (NSString *)stringByAppendingPathExtension:(NSString *)str;

Parameters

ext

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

/tmp/scratch.old

/tmp/scratch.old.tiff

/tmp/scratch.

/tmp/scratch..tiff

/tmp/

/tmp.tiff

scratch

scratch.tiff

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

+ pathWithComponents:

Returns a string built from the strings in a given array by concatenating them with a path separator between each pair.

pathComponents

The file-system path components of the receiver.

- completePathIntoString:caseSensitive:matchesIntoArray:filterTypes:

Interprets the receiver as a path in the file system and attempts to perform filename completion, returning a numeric value that indicates whether a match was possible, and by reference the longest path that matches the receiver.

fileSystemRepresentation

A file system-specific representation of the receiver.

- getFileSystemRepresentation:maxLength:

Interprets the receiver as a system-independent path and fills a buffer with a C-string in a format and encoding suitable for use with file-system calls.

absolutePath

A Boolean value that indicates whether the receiver represents an absolute path.

lastPathComponent

The last path component of the receiver.

pathExtension

The path extension, if any, of the string as interpreted as a path.

stringByAbbreviatingWithTildeInPath

A new string that replaces the current home directory portion of the current path with a tilde (~) character.

- stringByAppendingPathComponent:

Returns a new string made by appending to the receiver a given string.

stringByDeletingLastPathComponent

A new string made by deleting the last path component from the receiver, along with any final path separator.

stringByDeletingPathExtension

A new string made by deleting the extension (if any, and only the last) from the receiver.

stringByExpandingTildeInPath

A new string made by expanding the initial component of the receiver to its full path value.

stringByResolvingSymlinksInPath

A new string made from the receiver by resolving all symbolic links and standardizing path.

stringByStandardizingPath

A new string made by removing extraneous path components from the receiver.

- stringsByAppendingPaths:

Returns an array of strings made by separately appending to the receiver each string in a given array.