使用Xcode 3.2访问Unit Test Bundle中的文件

时间:2010-04-22 20:58:27

标签: iphone xcode

如何访问要在单元测试中使用的文件? (每当我询问更具体的信息时,我都无法回答任何问题。)

1 个答案:

答案 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];