Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

NSFileWrapperMBS.addFileWrapper(child as NSFileWrapperMBS) as String
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa MBS MacBase Plugin 16.0 Yes No No Yes, macOS only No
Function: Adds a child file wrapper to the receiver, which must be a directory file wrapper.
Notes:
child: File wrapper to add to the directory.

Returns Dictionary key used to store fileWrapper in the directory’s list of file wrappers. The dictionary key is a unique filename, which is the same as the passed-in file wrapper's preferred filename unless that name is already in use as a key in the directory’s dictionary of children. See Working with Directory Wrappers in File System Programming Guide for more information about the file-wrapper list structure.

Use this method to add an existing file wrapper as a child of a directory file wrapper. If the file wrapper does not have a preferred filename, set the preferredFilename property to give it one before calling addFileWrapper. To create a new file wrapper and add it to a directory, use the addRegularFileWithContents method.

Special Considerations
This method raises NSInternalInconsistencyException if the receiver is not a directory file wrapper.
This method raises NSInvalidArgumentException if the child file wrapper doesn’t have a preferred name.

Feedback, Comments & Corrections

NSFileWrapperMBS.addRegularFileWithContents(Data as MemoryBlock, preferredFilename as string) as String
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa MBS MacBase Plugin 16.0 Yes No No Yes, macOS only No
Function: Creates a regular-file file wrapper with the given contents and adds it to the receiver, which must be a directory file wrapper.
Notes:
data: Contents for the new regular-file file wrapper.
filename: Preferred filename for the new regular-file file wrapper.

Returns Dictionary key used to store the new file wrapper in the directory’s list of file wrappers. The dictionary key is a unique filename, which is the same as the passed-in file wrapper's preferred filename unless that name is already in use as a key in the directory's dictionary of children. See Working with Directory Wrappers in File System Programming Guide for more information about the file-wrapper list structure.

This is a convenience method. The default implementation allocates a new file wrapper, initializes it with initRegularFileWithContents, set its preferredFilename property, adds it to the directory with addFileWrapper, and returns what addFileWrapper returned.

This method raises NSInternalInconsistencyException if the receiver is not a directory file wrapper.
This method raises NSInvalidArgumentException if you pass nil or an empty value for filename.

Available in OS X v10.0 and later.

Feedback, Comments & Corrections

NSFileWrapperMBS.Constructor
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa MBS MacBase Plugin 15.0 Yes No No Yes, macOS only No
Function: The private constructor.

Feedback, Comments & Corrections

NSFileWrapperMBS.keyForFileWrapper(child as NSFileWrapperMBS) as String
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa MBS MacBase Plugin 16.0 Yes No No Yes, macOS only No
Function: Returns the dictionary key used by a directory to identify a given file wrapper.
Notes:
child: The child file wrapper for which you want the key.

Returns Dictionary key used to store the file wrapper in the directory’s list of file wrappers. The dictionary key is a unique filename, which may not be the same as the passed-in file wrapper's preferred filename if more than one file wrapper in the directory's dictionary of children has the same preferred filename. See Working with Directory Wrappers in File System Programming Guide for more information about the file-wrapper list structure. Returns nil if the file wrapper specified in child is not a child of the directory.

Special Considerations
This method raises NSInternalInconsistencyException if the receiver is not a directory file wrapper.

Feedback, Comments & Corrections

NSFileWrapperMBS.matchesContentsOfFile(File as Folderitem) as Boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa MBS MacBase Plugin 16.0 Yes No No Yes, macOS only No
Function: Indicates whether the contents of a file wrapper matches a directory, regular file, or symbolic link on disk.
Notes:
file: Folderitem of the file-system node with which to compare the file wrapper.

Returns true when the contents of the file wrapper match the contents of url, false otherwise.

The contents of files are not compared; matching of regular files is based on file modification dates. For a directory, children are compared against the files in the directory, recursively.

Because children of directory file wrappers are not read immediately by the initWithURL:options:error: method unless the NSFileWrapperReadingImmediate reading option is used, even a newly-created directory file wrapper might not have the same contents as the directory on disk. You can use this method to determine whether the file wrapper's contents in memory need to be updated.

If the file wrapper needs updating, use the readFromURL:options:error: method with the NSFileWrapperReadingImmediate reading option.

This table describes which attributes of the file wrapper and file-system node are compared to determine whether the file wrapper matches the node on disk:

File-wrapper typeComparison determinants
Regular fileModification date and access permissions.
DirectoryChildren (recursive).
Symbolic linkDestination pathname.

Available in OS X v10.6 and later.

Feedback, Comments & Corrections

NSFileWrapperMBS.matchesContentsOfURL(URL as String) as Boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa MBS MacBase Plugin 16.0 Yes No No Yes, macOS only No
Function: Indicates whether the contents of a file wrapper matches a directory, regular file, or symbolic link on disk.
Notes:
url: URL of the file-system node with which to compare the file wrapper.

Returns true when the contents of the file wrapper match the contents of url, false otherwise.

The contents of files are not compared; matching of regular files is based on file modification dates. For a directory, children are compared against the files in the directory, recursively.

Because children of directory file wrappers are not read immediately by the initWithURL:options:error: method unless the NSFileWrapperReadingImmediate reading option is used, even a newly-created directory file wrapper might not have the same contents as the directory on disk. You can use this method to determine whether the file wrapper's contents in memory need to be updated.

If the file wrapper needs updating, use the readFromURL:options:error: method with the NSFileWrapperReadingImmediate reading option.

This table describes which attributes of the file wrapper and file-system node are compared to determine whether the file wrapper matches the node on disk:

File-wrapper typeComparison determinants
Regular fileModification date and access permissions.
DirectoryChildren (recursive).
Symbolic linkDestination pathname.

Available in OS X v10.6 and later.

Feedback, Comments & Corrections

NSFileWrapperMBS.readFromFile(File as Folderitem, Options as Integer = 0, byref Error as NSErrorMBS) as Boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa MBS MacBase Plugin 16.0 Yes No No Yes, macOS only No
Function: Recursively rereads the entire contents of a file wrapper from the specified location on disk.
Notes:
File: Folderitem of the file-system node corresponding to the file wrapper.
options: Option flags for reading the node located at url.
Error: If an error occurs, upon return contains an NSError object that describes the problem.

Returns true if successful. If not successful, returns false after setting outError to an NSErrorMBS object that describes the reason why the file wrapper could not be reread.

When reading a directory, children are added and removed as necessary to match the file system.
Available in OS X v10.6 and later.

Feedback, Comments & Corrections

NSFileWrapperMBS.readFromURL(URL as String, Options as Integer = 0, byref Error as NSErrorMBS) as Boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa MBS MacBase Plugin 16.0 Yes No No Yes, macOS only No
Function: Recursively rereads the entire contents of a file wrapper from the specified location on disk.
Notes:
url: URL of the file-system node corresponding to the file wrapper.
options: Option flags for reading the node located at url.
Error: If an error occurs, upon return contains an NSError object that describes the problem.

Returns true if successful. If not successful, returns false after setting outError to an NSErrorMBS object that describes the reason why the file wrapper could not be reread.

When reading a directory, children are added and removed as necessary to match the file system.
Available in OS X v10.6 and later.

Feedback, Comments & Corrections

NSFileWrapperMBS.removeFileWrapper(child as NSFileWrapperMBS)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa MBS MacBase Plugin 16.0 Yes No No Yes, macOS only No
Function: Removes a child file wrapper from the receiver, which must be a directory file wrapper.
Notes: This method raises NSInternalInconsistencyException if the receiver is not a directory file wrapper.

Feedback, Comments & Corrections

NSFileWrapperMBS.writeToFile(File as Folderitem, Options as Integer = 0, originalContentsURL as FolderItem = nil, byref Error as NSErrorMBS) as Boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa MBS MacBase Plugin 16.0 Yes No No Yes, macOS only No
Function: Recursively writes the entire contents of a file wrapper to a given file-system URL.
Example:
// get styled text from htmlviewer
dim w as WebViewMBS = HTMLViewer1.WebViewMBS
dim f as WebFrameMBS = w.mainFrame
dim v as WebFrameViewMBS = f.frameView
dim d as WebDocumentViewMBS = v.documentView
dim n as NSAttributedStringMBS = d.attributedString


// package it
dim da as new Dictionary
da.Value(n.NSDocumentTypeDocumentAttribute) = n.NSRTFDTextDocumentType

dim e as NSErrorMBS
dim fw as NSFileWrapperMBS = n.fileWrapperFromRange(0, n.Length, da, e)
if e <> nil then
MsgBox e.LocalizedDescription
Return
end if

// write to disk
dim file as FolderItem = SpecialFolder.Desktop.Child("test.rtfd")
if fw.writeToFile(file, e) then
MsgBox "OK"
else
MsgBox e.LocalizedDescription
end if
Notes:
File: Folderitem of the file-system node to which the file wrapper’s contents are written.
options: Option flags for writing to the node located at url.
originalContentsURL: The location of a previous revision of the contents being written. The default implementation of this method attempts to avoid unnecessary I/O by writing hard links to regular files instead of actually writing out their contents when the contents have not changed. The child file wrappers must return accurate values when its filename property is accessed for this to work. Use the NSFileWrapperWritingWithNameUpdating writing option to increase the likelihood of that. Specify nil for this parameter if there is no earlier version of the contents or if you want to ensure that all the contents are written to files.
Error: If an error occurs, upon return contains an NSError object that describes the problem.

Returns true when the write operation is successful. If not successful, returns false after setting outError to an NSError object that describes the reason why the file wrapper’s contents could not be written.

Available in OS X v10.6 and later.

Feedback, Comments & Corrections

NSFileWrapperMBS.writeToURL(URL as String, Options as Integer = 0, originalContentsURL as String = "", byref Error as NSErrorMBS) as Boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Cocoa MBS MacBase Plugin 16.0 Yes No No Yes, macOS only No
Function: Recursively writes the entire contents of a file wrapper to a given file-system URL.
Notes:
url: URL of the file-system node to which the file wrapper’s contents are written.
options: Option flags for writing to the node located at url.
originalContentsURL: The location of a previous revision of the contents being written. The default implementation of this method attempts to avoid unnecessary I/O by writing hard links to regular files instead of actually writing out their contents when the contents have not changed. The child file wrappers must return accurate values when its filename property is accessed for this to work. Use the NSFileWrapperWritingWithNameUpdating writing option to increase the likelihood of that. Specify nil for this parameter if there is no earlier version of the contents or if you want to ensure that all the contents are written to files.
Error: If an error occurs, upon return contains an NSError object that describes the problem.

Returns true when the write operation is successful. If not successful, returns false after setting outError to an NSError object that describes the reason why the file wrapper’s contents could not be written.

Available in OS X v10.6 and later.

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacBase Plugin.




Links
MBS Xojo Chart Plugins