13.07.2015 Views

Beginning Objective-C pdf - EBook Free Download

Beginning Objective-C pdf - EBook Free Download

Beginning Objective-C pdf - EBook Free Download

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

124CHAPTER 5: Using the Filesystem// Get a temporary folder to write out our new data ready to swap out with the oldNSURL * swapFolder = [[NSFileManager defaultManager] URLForDirectory:NSItemReplacementDirectoryinDomain: NSUserDomainMaskappropriateForURL: itemURLcreate: YESerror: &error];NSURL * tmpItemURL = [swapFolder URLByAppendingPathComponent:[itemURL lastPathComponent]];// Generate the new content[self generateContentAtURL: tmpItemURL];// now swap the new item with the old[[NSFileManager defaultManager] replaceItemAtURL: itemURLwithItemAtURL: tmpItemURLbackupItemName: niloptions: 0replacementItemURL: NULLerror: &error];Aside from these very useful methods are those found in Table 5-7, for moving items aroundon the filesystem and for accessing their attributes. The attributes available through theNSFileManager API are fewer in number than those available from NSURL, however, and arenot cached like those obtained from a URL object. It is also worth noting that NSFileManagerhas a delegation protocol that allows you to confirm many operations before they happenand to gracefully handle any errors that might occur. For more details on that,see .Table 5-7. More NSFileManager APIsMethodcopyItemAtURL:toURL:error:moveItemAtURL:toURL:error:removeItemAtURL:error:linkItemAtURL:toURL:error:trashItemAtURL:resultingItemURL:error:createSymbolicLinkAtURL:withDestinationURL:error:createDirectoryAtPath:withIntermediateDirectories:attributes:error:attributesOfItemAtPath:error:DescriptionMakes a copy of a given item at the target URL.Moves an item to a new location.Deletes the file or folder at a given URL.Creates a hard link between an existing item and anew location.Moves the specified item to the user’s Trash folder.Available in OS X 10.8Creates a symbolic link to a given URL at the specifiedlocation.Creates a new folder with the given attributes,optionally creating any missing parent folders.Obtains an NSDictionary containing various attributesof the file at the given path.www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!