如何访问要在单元测试中使用的文件? (每当我询问更具体的信息时,我都无法回答任何问题。)
答案 0 :(得分:2)
你到底想要做什么? 如果您尝试转储数据文件并重新读取它:
// To Dump:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"/MyDataFile"];
[NSKeyedArchiver archiveRootObject:mediaManager toFile:filePath];
// To Re-Load:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"/MyDataFile"];
myReciever = [[NSKeyedUnarchiver unarchiveObjectWithFile:filePath] retain];