How to update an attribute or a key for a file while saving it in to documents directory

▼魔方 西西 提交于 2019-12-11 14:35:01

问题


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.

  1. 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.

  2. 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.

  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!