路径:NSString *parh = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"searchHistory.plist"];
获取:NSMutableArray *searchHistories = [NSKeyedUnarchiver unarchiveObjectWithFile:parh];
插入某条:[searchHistories removeObject:@"historyText"];
[searchHistories insertObject:@"historyText" atIndex:0];
[NSKeyedArchiver archiveRootObject:searchHistories toFile:parh];
删除某条:[searchHistories removeObject:@"historyText"];
[NSKeyedArchiver archiveRootObject:searchHistories toFile:parh];
清空:[searchHistories removeAllObjects];
[NSKeyedArchiver archiveRootObject:searchHistories toFile:parh];
Swift搜索历史记录操作
本文详细介绍了如何在Swift中使用Objective-C桥接头文件来操作搜索历史记录。具体包括获取搜索历史路径、读取和写入搜索历史记录、插入、删除特定记录以及清空整个历史记录的方法。
2万+

被折叠的 条评论
为什么被折叠?



