2 // HMHistoryItemCleaner.m
5 // Created by Hori,Masaki on 2016/06/27.
6 // Copyright © 2016年 Hori,Masaki. All rights reserved.
9 #import "HMHistoryItemCleaner.h"
11 #import "HMUserDefaults.h"
13 #import "HMLocalDataStore.h"
16 @implementation HMHistoryItemCleaner
18 - (void)cleanOldHistoryItems
20 if(!HMStandardDefaults.cleanOldHistoryItems) return;
22 HMLocalDataStore *store = [HMLocalDataStore oneTimeEditor];
24 NSDate *date = [NSDate dateWithTimeIntervalSinceNow:-1 * HMStandardDefaults.cleanSiceDays * 24 * 60 * 60];
25 NSPredicate *p01 = [NSPredicate predicateWithFormat:@"date < %@", date];
26 NSPredicate *p02 = [NSPredicate predicateWithFormat:@"mark = 0 || mark = nil"];
27 NSPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[p01, p02]];
30 NSArray<NSManagedObject *> *array = [store objectsWithEntityName:@"KaihatuHistory"
34 for(NSManagedObject *obj in array) {
35 [store deleteObject:obj];
38 NSLog(@"%s ERROR: KaihatuHistory, %@", __PRETTY_FUNCTION__, error);
42 array = [store objectsWithEntityName:@"KenzoHistory"
46 for(NSManagedObject *obj in array) {
47 [store deleteObject:obj];
50 NSLog(@"%s ERROR: KenzoHistory, %@", __PRETTY_FUNCTION__, error);
53 NSArray *area = @[@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9"];
54 NSPredicate *p03 = [NSPredicate predicateWithFormat:@"mapArea IN %@", area];
55 predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[predicate, p03]];
58 array = [store objectsWithEntityName:@"DropShipHistory"
62 for(NSManagedObject *obj in array) {
63 [store deleteObject:obj];
66 NSLog(@"%s ERROR: DropShipHistory, %@", __PRETTY_FUNCTION__, error);