有没有办法记录R中的变量及其创建/修改日期? 因为我使用了流利的.RData文件,但有时需要根据它的年龄来更新值。
答案 0 :(得分:3)
尝试@interface ViewController ()
@property (nonatomic, strong) NSMutableDictionary *objectsForDates;
@property (nonatomic, strong) NSArray *dates;
@property (nonatomic, strong) NSDateFormatter *formatter;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// set formatter for output
self.formatter = [[NSDateFormatter alloc] init];
[self.formatter setDateFormat:[NSDateFormatter dateFormatFromTemplate:@"EEEdMMMyyyy" options:0 locale:[NSLocale currentLocale]]];
self.formatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
// perform request
NSURL *url = [NSURL URLWithString:@"http://borindatabase.000webhostapp.com/jsonData.php"];
[[[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error || !data) {
NSLog(@"networkError: %@", error);
return;
}
NSError *parseError;
NSArray *values = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
if (![values isKindOfClass:[NSArray class]]) {
NSLog(@"parseError: %@", parseError);
}
// build dictionary of objects, keyed by date
NSMutableDictionary *objectsForDates = [[NSMutableDictionary alloc] init];
for (NSDictionary *value in values) {
Location *object = [[Location alloc] initWithDictionary:value];
NSMutableArray *objects = objectsForDates[object.date];
if (!objects) {
objects = [[NSMutableArray alloc] init];
objectsForDates[object.date] = objects;
}
[objects addObject:object];
}
// build sorted array of dates in descending order
NSArray *dates = [[objectsForDates allKeys] sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
return [obj2 compare:obj1];
}];
// now update UI
dispatch_async(dispatch_get_main_queue(), ^{
self.objectsForDates = objectsForDates;
self.dates = dates;
[self.tableView reloadData];
});
}] resume];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [self.dates count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.objectsForDates[self.dates[section]] count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [self.formatter stringFromDate:self.dates[section]];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
Location *object = self.objectsForDates[self.dates[indexPath.section]][indexPath.row];
cell.textLabel.text = object.home;
return cell;
}
@end
:
获取上次修改时间:
file.info()
如果你想知道你的file.info('path/to/file.Rdata')$mtime
对象中的个别变量何时最后由R定义,我知道要做的就是手动添加这样的元数据:
.RData