Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/AppKit.framework |
Availability | Available in Mac OS X v10.0 and later. |
Companion guide | |
Declared in | NSFileWrapper.h |
Related sample code |
The NSFileWrapper
class provides access to the attributes and contents of filesystem nodes. A filesystem node is a file, directory, or symbolic link. Instances of this class are known as file wrappers.
File wrappers represent a filesystem node as an object that can be displayed as an image (and possibly edited in place), saved to the filesystem, or transmitted to another application. It can also store an icon for representing the node in a document or in a dragging operation.
There are three types of file wrappers:
Regular-file file wrapper: Represents a regular file node.
Directory file wrapper: Represents a directory node.
Symbolic-link file wrapper: Represents a symbolic-link node.
A file wrapper has these attributes:
Filename. Name of the filesystem node the file wrapper represents.
Icon: Image that represents the file wrapper to the user.
Filesystem attributes. See NSFileManager
for information on the contents of the attributes dictionary.
Regular-file contents. Applicable only to regular-file file wrappers.
File wrappers. Applicable only to directory file wrappers.
Destination node. Applicable only to symbolic-link file wrappers.
This class does not have a designated initializer.
– initWithPath:
– initDirectoryWithFileWrappers:
– initRegularFileWithContents:
– initSymbolicLinkWithDestination:
– initWithSerializedRepresentation:
– fileWrappers
– addFileWrapper:
– removeFileWrapper:
– addFileWithPath:
– addRegularFileWithContents:preferredFilename:
– addSymbolicLinkWithDestination:preferredFilename:
– keyForFileWrapper:
– symbolicLinkDestination
– filename
– setFilename:
– preferredFilename
– setPreferredFilename:
– icon
– setIcon:
– fileAttributes
– setFileAttributes:
– regularFileContents
Creates a file wrapper from a given filesystem node and adds it to the receiver, which must be a directory file wrapper.
- (NSString *)addFileWithPath:(NSString *)node
Filesystem node from which to create the file wrapper to add to the receiver.
Dictionary key used to store the new file wrapper in the receiver’s list of file wrappers. See Working With Directory Wrappers for more information.
This method raises NSInternalInconsistencyException
when the receiver is not a directory file wrapper.
– addRegularFileWithContents:preferredFilename:
– addSymbolicLinkWithDestination:preferredFilename:
– removeFileWrapper:
– fileWrappers
NSFileWrapper.h
Adds a file wrapper to the receiver, which must be a directory file wrapper.
- (NSString *)addFileWrapper:(NSFileWrapper *)fileWrapper
File wrapper to add to the receiver. Raises NSInvalidArgumentException
when the file wrapper doesn’t have a preferred name.
Dictionary key used to store fileWrapper in the receiver’s list of file wrappers. See Working With Directory Wrappers for more information.
This method raises NSInternalInconsistencyException
when the receiver is not a directory file wrapper.
– addFileWithPath:
– addRegularFileWithContents:preferredFilename:
– addSymbolicLinkWithDestination:preferredFilename:
– removeFileWrapper:
– fileWrappers
– preferredFilename
NSFileWrapper.h
Creates a regular-file file wrapper with the given contents and adds it to the receiver, which must be a directory file wrapper.
- (NSString *)addRegularFileWithContents:(NSData *)regularFileContents preferredFilename:(NSString *)preferredFilename
Contents for the new regular-file file wrapper.
Preferred filename for the new regular-file file wrapper. A nil
or empty value raises NSInvalidArgumentException
.
Dictionary key used to store the new file wrapper in the receiver’s list of file wrappers.
This method raises NSInternalInconsistencyException
when the receiver is not a directory file wrapper.
– addFileWithPath:
– addSymbolicLinkWithDestination:preferredFilename:
– removeFileWrapper:
– fileWrappers
NSFileWrapper.h
Creates a symbolic-link file wrapper pointing to a given filesystem node and adds it to the receiver, which must be a directory file wrapper.
- (NSString *)addSymbolicLinkWithDestination:(NSString *)node preferredFilename:(NSString *)preferredFilename
Pathname the new symbolic-link file wrapper is to reference.
Preferred filename for the new symbolic-link file wrapper. A nil
or empty value raises NSInvalidArgumentException
.
Dictionary key used to store the new file wrapper in the receiver’s list of file wrappers. See Working With Directory Wrappers for more information.
This method raises NSInternalInconsistencyException
when the receiver is not a directory file wrapper.
– addFileWithPath:
– addFileWrapper:
– addRegularFileWithContents:preferredFilename:
– removeFileWrapper:
– fileWrappers
NSFileWrapper.h
Provides the receiver’s file attributes.
- (NSDictionary *)fileAttributes
See the NSFileManager
class for information on the contents of the attributes dictionary.
NSFileWrapper.h
Provides the receiver’s filename.
- (NSString *)filename
The receiver’s filename; nil
when the receiver has no corresponding node.
The filename is used for record-keeping purposes only and is set automatically when the file wrapper is created from the filesystem using initWithPath:
and when it’s saved to the filesystem using writeToFile:atomically:updateFilenames:
(although this method allows you to request that the filename not be updated).
NSFileWrapper.h
Provides the file wrappers contained by the receiver, which must be a directory file wrapper.
- (NSDictionary *)fileWrappers
Keyed list of file wrappers. See Working With Directory Wrappers for more information.
This method raises NSInternalInconsistencyException
when the receiver is not a directory file wrapper.
NSFileWrapper.h
Provides an image that represents the receiver to the user.
- (NSImage *)icon
Image that represents the receiver; nil
when the receiver has no icon.
You don’t have to use this image; for example, a file viewer typically looks up icons automatically based on file extensions, and so wouldn’t need this image. Similarly, if a file wrapper represents an image file, you can display the image directly rather than a file icon.
NSFileWrapper.h
Initializes the receiver as a directory file wrapper, with a given file-wrapper list.
- (id)initDirectoryWithFileWrappers:(NSDictionary *)fileWrappers
Keyed list of file wrappers with which to initialize the receiver. See Working With Directory Wrappers for details about the file-wrapper list structure.
Initialized file wrapper for fileWrappers.
After initialization, the receiver is not associated to a filesystem node until you save it using writeToFile:atomically:updateFilenames:
. It’s also initialized with open permissions; anyone can read, write, or change directory to the disk representations that it saves.
If any file wrapper in fileWrappers doesn’t have a preferred name, its preferred name is automatically set to its corresponding dictionary key in fileWrappers.
NSFileWrapper.h
Initializes the receiver as a regular-file file wrapper.
- (id)initRegularFileWithContents:(NSData *)regularFileContents
Contents for the receiver.
Initialized regular-file file wrapper containing regularFileContents.
After initialization, the receiver is not associated to a filesystem node until you save it using writeToFile:atomically:updateFilenames:
. It’s also initialized with open permissions; anyone can read or write the disk representations that it saves.
NSFileWrapper.h
Initializes the receiver as a symbolic-link file wrapper.
- (id)initSymbolicLinkWithDestination:(NSString *)node
Pathname the receiver is to represent.
Initialized symbolic-link file wrapper referencing node.
The receiver is not associated to a filesystem node until you save it using writeToFile:atomically:updateFilenames:
. It’s also initialized with open permissions; anyone can read or write the disk representations it saves.
NSFileWrapper.h
Initializes the receiver with a given node.
- (id)initWithPath:(NSString *)node
Pathname of the node the receiver is to represent.
File wrapper for node.
If node is a directory, this method recursively creates file wrappers for each node within that directory.
NSFileWrapper.h
Initializes the receiver from given serialized data.
- (id)initWithSerializedRepresentation:(NSData *)serializedRepresentation
Serialized representation of a file wrapper in the format used for the NSFileContentsPboardType
pasteboard type. Data of this format is returned by such methods as serializedRepresentation
and RTFDFromRange:documentAttributes:
(NSAttributedString
).
File wrapper initialized from serializedRepresentation.
The receiver is not associated to a filesystem node until you save it using writeToFile:atomically:updateFilenames:
.
NSFileWrapper.h
Indicates whether the receiver is a directory file wrapper.
- (BOOL)isDirectory
YES
when the receiver is a directory file wrapper, NO
otherwise.
NSFileWrapper.h
Indicates whether the receiver is a regular-file file wrapper.
- (BOOL)isRegularFile
YES
when the receiver is a regular-file wrapper, NO
otherwise.
NSFileWrapper.h
Indicates whether the receiver is a symbolic-link file wrapper.
- (BOOL)isSymbolicLink
YES
when the receiver is a symbolic-link file wrapper, NO
otherwise.
NSFileWrapper.h
Provides a key used by the receiver to identify a given file wrapper. The receiver must be a dictionary file wrapper.
- (NSString *)keyForFileWrapper:(NSFileWrapper *)fileWrapper
File wrapper in question.
Key (not necessarily the filename) that identifies fileWrapper within the receiver’s list of file wrappers. See Working With Directory Wrappers for more information.
This method raises NSInternalInconsistencyException
when the receiver is not a directory file wrapper.
NSFileWrapper.h
Indicates whether the receiver needs to be updated to match a given filesystem node.
- (BOOL)needsToBeUpdatedFromPath:(NSString *)node
Filesystem node with which to compare the receiver.
YES
when the receiver needs to be updated to match node, NO
otherwise.
This table describes which attributes of the receiver and node are compared to determine whether the receiver needs to be updated:
File-wrapper type | Comparison determinants |
---|---|
Regular file | Modification date and access permissions. |
Directory | Member hierarchy (recursive). |
Symbolic link | Destination pathname. |
NSFileWrapper.h
Provides the receiver’s preferred filename.
- (NSString *)preferredFilename
The receiver’s preferred filename.
This name is used as the key when a file wrapper is added to a directory wrapper. However, if another file wrapper with the same preferred name already exists in the directory file wrapper when the receiver is added, the dictionary key and filename assigned may differ from the preferred filename.
NSFileWrapper.h
Provides the contents of the receiver’s filesystem node. The receiver must be a regular-file file wrapper.
- (NSData *)regularFileContents
Contents of the filesystem node the receiver represents.
This method raises NSInternalInconsistencyException
when the receiver is not a regular-file file wrapper.
NSFileWrapper.h
Removes a file wrapper from the receiver, which must be a directory file wrapper.
- (void)removeFileWrapper:(NSFileWrapper *)fileWrapper
File wrapper to remove from the receiver.
This method raises NSInternalInconsistencyException
when the receiver is not a directory file wrapper.
– addFileWithPath:
– addFileWrapper:
– addRegularFileWithContents:preferredFilename:
– addSymbolicLinkWithDestination:preferredFilename:
– fileWrappers
NSFileWrapper.h
Provides the receiver’s contents as an opaque collection of data.
- (NSData *)serializedRepresentation
The receiver’s contents in the format used for the pasteboard type NSFileContentsPboardType
.
NSFileWrapper.h
Specifies the receiver’s file attributes.
- (void)setFileAttributes:(NSDictionary *)fileAttributes
File attributes for the receiver.
NSFileWrapper.h
Specifies the receiver’s filename.
- (void)setFilename:(NSString *)filename
Filename for the receiver. A nil
or empty value raises NSInvalidArgumentException
.
NSFileWrapper.h
Specifies the image to be used to represent the receiver to the user.
- (void)setIcon:(NSImage *)icon
Image that is to represent the receiver to the user.
NSFileWrapper.h
Specifies the receiver’s preferred filename.
- (void)setPreferredFilename:(NSString *)preferredFilename
Preferred filename for the receiver. A nil
or empty value raises NSInvalidArgumentException
.
NSFileWrapper.h
Provides the pathname referenced by the receiver, which must be a symbolic-link file wrapper.
- (NSString *)symbolicLinkDestination
Pathname the receiver references (the destination of the symbolic link the receiver represents).
This method raises NSInternalInconsistencyException
when the receiver is not a symbolic-link file wrapper.
NSFileWrapper.h
Updates the receiver to match a given filesystem node.
- (BOOL)updateFromPath:(NSString *)path
YES
if the update is carried out, NO
if it isn’t needed.
For a directory file wrapper, the contained file wrappers are also sent updateFromPath:
messages. If nodes in the corresponding directory on the filesystem have been added or removed, corresponding file wrappers are released or created as needed.
– needsToBeUpdatedFromPath:
– updateAttachmentsFromPath:
(NSAttributedString)NSFileWrapper.h
Writes the receiver’s contents to a given filesystem node.
- (BOOL)writeToFile:(NSString *)node atomically:(BOOL)atomically updateFilenames:(BOOL)updateNames
Pathname of the filesystem node to which the receiver’s contents are written.
YES
to write the file safely so that:
An existing file is not overwritten
The method fails if the file cannot be written in its entirety
NO
to overwrite an existing file and ignore incomplete writes.
YES
to update the receiver’s filenames (its filename and—for directory file wrappers—the filenames of its sub–file wrappers) be changed to the filenames of the corresponding nodes in the filesystem, after a successful write operation. Use this in Save or Save As operations.
NO
to specify that the receiver’s filenames not be updated. Use this in Save To operations.
YES
when the write operation is successful, NO
otherwise.
NSFileWrapper.h
© 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-10-15)