问题
Hi I'm using Dropbox API for my iOS project, here through dropbox iOS SDK's REST calls I'm getting my data and I'm caching my files in to my DocumentsDirectory, so as to avoid delay of loading file from server every time by service calls.
So once a file downloaded from dropbox server I'll be keeping it inside my apps documents directory and for further reference I'm fetching from my documents directory.
Here the problem is whenever a file is updated or modified a new revision number i will get some how i need to save this revision number along with the respective file, so that next time when i want this file i will check the revision number, if it matches then take from my local directory else invoke service.
Now how can i save(update) this revision number string.
I tried below snippet while saving a file to Documents directory but setAttributes can't add userDefined file attribute properties, we can only update default properties
NSDictionary *revisionDict = [NSDictionary dictionaryWithObject:item.rev forKey:@"revision"];
[[NSFileManager defaultManager] setAttributes:revisionDict ofItemAtPath:DocDirPath error:nil];
回答1:
If you want to manipulate the extended attributes you must use BSD level APIs. Specifically the header <sys/xattr.h>
and functions like getxattr
, setxattr
, listxattr
, removexattr
. Documentation is in the corresponding man
pages.
来源:https://stackoverflow.com/questions/12403857/how-to-update-an-attribute-or-a-key-for-a-file-while-saving-it-in-to-documents-d