gpt4 book ai didi

ios - 在 iOS 中创建文件和目录

转载 作者:行者123 更新时间:2023-11-29 01:54:26 25 4
gpt4 key购买 nike

我正在使用 Xcode 开发 iOS 应用程序。在接口(interface)实现之一(比如接口(interface) A)中,我在文档目录下创建文件。我可以从接口(interface) A 访问它。但是,如果我尝试访问我在接口(interface) A 中创建的文件,我会从另一个接口(interface)(比如接口(interface) B)获取文件未找到。下面给出了我在接口(interface) B 中使用的访问文件内容的方法

- (void)loadData{

if ([[NSFileManager defaultManager] fileExistsAtPath:_appFile]) {
NSLog(@"Directory Exists");
_appFile = [_appFile stringByAppendingPathComponent:@"info.txt"];
if ([[NSFileManager defaultManager] fileExistsAtPath:_appFile]) {

NSLog(@"File Exists");
NSData *data = [[NSData alloc] initWithContentsOfFile:_appFile];

if (data!=nil) {
NSMutableDictionary *dict = (NSMutableDictionary *)
[NSKeyedUnarchiver unarchiveObjectWithData:data];
ToDoItem *item = [dict objectForKey:@"0"];
[_toDoItems addObject:item];
}
else{
NSLog(@"Data is empty");
}
}
else{
NSLog(@"File not exists");
}
}
else{
NSLog(@"Directory not exists");
}

}

我收到上面的消息“目录不存在”。这个目录和我在接口(interface)A中引用的目录是一样的。但是从接口(interface)B无法访问。谁能告诉我是什么原因。

提前致谢

最佳答案

遵循 MVC 模式。编写一个类,它将处理所有与文件相关的东西,并将文件名传递给该类并获取文件。(您的 loadData 方法将包含在内)因为如果一个是从一个接口(interface)访问的,那么它也必须是从另一个接口(interface)访问的。

关于ios - 在 iOS 中创建文件和目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31045173/

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