//拼接路径
- (NSString *)dataFilePath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:@“searchPath”];
- (NSString *)dataFilePath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:@“searchPath”];
}
// 初始化数组
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
NSMutableArray *arr = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
[_searchHistory addObjectsFromArray:arr];
[arr release];
}
// 把数组写入文件,时时保存搜索记录
[_searchHistory addObject:number1];
[_searchHistory writeToFile:[self dataFilePath] atomically:YES];
// 清空历史记录
[_searchHistory removeAllObjects];
[_searchHistory writeToFile:[self dataFilePath] atomically:YES];