gpt4 book ai didi

ios - NSKeyedArchiver archiveRootObject 和 NSFileProtectionComplete/NSFileProtectionCompleteUnlessOpen

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:10:50 26 4
gpt4 key购买 nike

是否真的可以调用 NSKeyedArchiver archiveRootObject 并使用数据保护 API 将文件属性设置为 NSFileProtectionComplete 或 NSFileProtectionCompleteUnlessOpen ?

最佳答案

首先尝试将对象写入特定位置,在本例中为 docFile(设置为文档目录)。然后将文件属性应用于 docFile。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex: 0];
NSString* docFile = [docDir stringByAppendingPathComponent: @"Somefile.plist"];
NSError* error;

if([NSKeyedArchiver archiveRootObject:tempData toFile:docFile]) {

NSDictionary *fileAttributes = [NSDictionary
dictionaryWithObject:NSFileProtectionComplete
forKey:NSFileProtectionKey];
if([[NSFileManager defaultManager] setAttributes:fileAttributes
ofItemAtPath:docFile error: &error]) {
NSLog(@"Success");
}
else {
NSLog@(%@", error);
}
}

关于ios - NSKeyedArchiver archiveRootObject 和 NSFileProtectionComplete/NSFileProtectionCompleteUnlessOpen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13477106/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com