From bfdec870c2e77b8b816cc986abffa947e95b1897 Mon Sep 17 00:00:00 2001 From: masakih Date: Sun, 18 Dec 2016 19:37:41 +0900 Subject: [PATCH] =?utf8?q?HMHistoryItemCleaner=E3=82=92Swift=E3=81=AB?= =?utf8?q?=E5=A4=89=E6=8F=9B=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- KCD.xcodeproj/project.pbxproj | 26 ++++++++++++---- KCD/HMAppDelegate.m | 3 +- KCD/HMHistoryItemCleaner.h | 15 --------- KCD/HMHistoryItemCleaner.m | 69 ------------------------------------------ KCD/HMHistoryItemCleaner.swift | 56 ++++++++++++++++++++++++++++++++++ KCD/KCD-Bridging-Header.h | 9 ++++++ 6 files changed, 87 insertions(+), 91 deletions(-) delete mode 100644 KCD/HMHistoryItemCleaner.h delete mode 100644 KCD/HMHistoryItemCleaner.m create mode 100644 KCD/HMHistoryItemCleaner.swift create mode 100644 KCD/KCD-Bridging-Header.h diff --git a/KCD.xcodeproj/project.pbxproj b/KCD.xcodeproj/project.pbxproj index f994a03b..fe994d0f 100644 --- a/KCD.xcodeproj/project.pbxproj +++ b/KCD.xcodeproj/project.pbxproj @@ -38,7 +38,6 @@ F4268034195332A000B2C27F /* HMPowerUpCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4268033195332A000B2C27F /* HMPowerUpCommand.m */; }; F42680371957000200B2C27F /* HMTimerCountFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = F42680361957000200B2C27F /* HMTimerCountFormatter.m */; }; F42CBB231D1F967F004C2AE2 /* HMHistoryMarkTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = F42CBB221D1F967F004C2AE2 /* HMHistoryMarkTransformer.m */; }; - F42CBB261D21583C004C2AE2 /* HMHistoryItemCleaner.m in Sources */ = {isa = PBXBuildFile; fileRef = F42CBB251D21583C004C2AE2 /* HMHistoryItemCleaner.m */; }; F431E9761DF3AC1C00FB56AE /* HMSetActionCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F431E9751DF3AC1C00FB56AE /* HMSetActionCommand.m */; }; F431E9791DF3CD1B00FB56AE /* HMActinKindTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = F431E9781DF3CD1B00FB56AE /* HMActinKindTransformer.m */; }; F431E97C1DF3D2E100FB56AE /* HMAreaNameTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = F431E97B1DF3D2E100FB56AE /* HMAreaNameTransformer.m */; }; @@ -74,6 +73,7 @@ F4513EF318B991F800073552 /* HMMemberBasicCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4513EF218B991F800073552 /* HMMemberBasicCommand.m */; }; F4513EF618B9F29800073552 /* HMMemberShipCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4513EF518B9F29800073552 /* HMMemberShipCommand.m */; }; F4513EFA18BB699700073552 /* HMShipWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = F4513EF818BB699700073552 /* HMShipWindowController.m */; }; + F45F3BE11E067A870009434E /* HMHistoryItemCleaner.swift in Sources */ = {isa = PBXBuildFile; fileRef = F45F3BE01E067A870009434E /* HMHistoryItemCleaner.swift */; }; F4649FC91DBC51EF0097AEBF /* HMScreenshotListViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4649FCB1DBC51EF0097AEBF /* HMScreenshotListViewController.xib */; }; F4649FCE1DBC52600097AEBF /* HMScreenshotDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4649FD01DBC52600097AEBF /* HMScreenshotDetailViewController.xib */; }; F4649FD31DBC52A50097AEBF /* HMScreenshotEditorViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4649FD51DBC52A50097AEBF /* HMScreenshotEditorViewController.xib */; }; @@ -380,8 +380,6 @@ F42CBB201D1ED41D004C2AE2 /* LocalData 3.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "LocalData 3.xcdatamodel"; sourceTree = ""; }; F42CBB211D1F967F004C2AE2 /* HMHistoryMarkTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMHistoryMarkTransformer.h; sourceTree = ""; }; F42CBB221D1F967F004C2AE2 /* HMHistoryMarkTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMHistoryMarkTransformer.m; sourceTree = ""; }; - F42CBB241D21583C004C2AE2 /* HMHistoryItemCleaner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMHistoryItemCleaner.h; sourceTree = ""; }; - F42CBB251D21583C004C2AE2 /* HMHistoryItemCleaner.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMHistoryItemCleaner.m; sourceTree = ""; }; F431E9741DF3AC1C00FB56AE /* HMSetActionCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMSetActionCommand.h; sourceTree = ""; }; F431E9751DF3AC1C00FB56AE /* HMSetActionCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMSetActionCommand.m; sourceTree = ""; }; F431E9771DF3CD1B00FB56AE /* HMActinKindTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMActinKindTransformer.h; sourceTree = ""; }; @@ -450,6 +448,8 @@ F4513EF518B9F29800073552 /* HMMemberShipCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMMemberShipCommand.m; sourceTree = ""; }; F4513EF718BB699700073552 /* HMShipWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMShipWindowController.h; sourceTree = ""; }; F4513EF818BB699700073552 /* HMShipWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMShipWindowController.m; sourceTree = ""; }; + F45F3BDD1E0679D80009434E /* KCD-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "KCD-Bridging-Header.h"; sourceTree = ""; }; + F45F3BE01E067A870009434E /* HMHistoryItemCleaner.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMHistoryItemCleaner.swift; sourceTree = ""; }; F4649FC81DBC51A90097AEBF /* zh-Hant-TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant-TW"; path = "zh-Hant-TW.lproj/HMScreenshotListWindowController.strings"; sourceTree = ""; }; F4649FCD1DBC51F30097AEBF /* zh-Hant-TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant-TW"; path = "zh-Hant-TW.lproj/HMScreenshotListViewController.strings"; sourceTree = ""; }; F4649FD21DBC52630097AEBF /* zh-Hant-TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant-TW"; path = "zh-Hant-TW.lproj/HMScreenshotDetailViewController.strings"; sourceTree = ""; }; @@ -1231,8 +1231,7 @@ F4F9F89A1C6CB7D400D0EE76 /* HMFleet.m */, F4F9F8A11C70AFB600D0EE76 /* HMFleetManager.h */, F4F9F8A21C70AFB600D0EE76 /* HMFleetManager.m */, - F42CBB241D21583C004C2AE2 /* HMHistoryItemCleaner.h */, - F42CBB251D21583C004C2AE2 /* HMHistoryItemCleaner.m */, + F45F3BE01E067A870009434E /* HMHistoryItemCleaner.swift */, F4C2ACA31D7167C2007BFE90 /* HMTimeSignalNotifier.h */, F4C2ACA41D7167C2007BFE90 /* HMTimeSignalNotifier.m */, F45F3BDC1E0575170009434E /* TouchBar */, @@ -1240,6 +1239,7 @@ F4BEEEA918D890660006F70C /* UI */, F4BEEEA818D88FF30006F70C /* CoreData */, F4BDEB4D187252F30069D0CE /* Supporting Files */, + F45F3BDD1E0679D80009434E /* KCD-Bridging-Header.h */, ); path = KCD; sourceTree = ""; @@ -1737,6 +1737,9 @@ LastUpgradeCheck = 0800; ORGANIZATIONNAME = "Hori,Masaki"; TargetAttributes = { + F4BDEB42187252F30069D0CE = { + LastSwiftMigration = 0820; + }; F4BDEB63187252F30069D0CE = { TestTargetID = F4BDEB42187252F30069D0CE; }; @@ -1853,6 +1856,7 @@ F4513EE818B77A5300073552 /* HMMemberKDockCommand.m in Sources */, F4F9F87E1C6B5E4A00D0EE76 /* HMKCMasterSType.m in Sources */, F431E9791DF3CD1B00FB56AE /* HMActinKindTransformer.m in Sources */, + F45F3BE11E067A870009434E /* HMHistoryItemCleaner.swift in Sources */, F426802B194D0F4800B2C27F /* HMMemberShip2Command.m in Sources */, F4A9E8001D045C0E00F91746 /* HMBridgeViewController.m in Sources */, F4AA06101931869E00844688 /* HMBattleResultCommand.m in Sources */, @@ -1977,7 +1981,6 @@ F431E9761DF3AC1C00FB56AE /* HMSetActionCommand.m in Sources */, F46F104118A9B85E0063E503 /* HMJSONNode.m in Sources */, F4BEEFDB1B0A219E004702B8 /* HMShipDeckCommand.m in Sources */, - F42CBB261D21583C004C2AE2 /* HMHistoryItemCleaner.m in Sources */, F43F3D461A33F7D400D6DAF7 /* HMResetSortieCommand.m in Sources */, F4131ECF190F5C08004F7F9A /* HMStoreCreateSlotItemHistoryCommand.m in Sources */, F4AA05FB192B92C800844688 /* Temporary.xcdatamodeld in Sources */, @@ -2558,6 +2561,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; COMBINE_HIDPI_IMAGES = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "KCD/KCD-Prefix.pch"; @@ -2567,9 +2571,13 @@ "COREDATA_STORE_TYPE=0", ); INFOPLIST_FILE = "KCD/KCD-Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = "com.masakih.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "KCD/KCD-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; WRAPPER_EXTENSION = app; }; name = Debug; @@ -2578,6 +2586,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; COMBINE_HIDPI_IMAGES = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "KCD/KCD-Prefix.pch"; @@ -2586,9 +2595,12 @@ "UI_TEST=0", ); INFOPLIST_FILE = "KCD/KCD-Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = "com.masakih.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "KCD/KCD-Bridging-Header.h"; + SWIFT_VERSION = 3.0; WRAPPER_EXTENSION = app; }; name = Release; @@ -2596,6 +2608,7 @@ F4BDEB78187252F30069D0CE /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/KCD.app/Contents/MacOS/KCD"; COMBINE_HIDPI_IMAGES = YES; FRAMEWORK_SEARCH_PATHS = ( @@ -2619,6 +2632,7 @@ F4BDEB79187252F30069D0CE /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/KCD.app/Contents/MacOS/KCD"; COMBINE_HIDPI_IMAGES = YES; FRAMEWORK_SEARCH_PATHS = ( diff --git a/KCD/HMAppDelegate.m b/KCD/HMAppDelegate.m index 158d7771..b3027004 100644 --- a/KCD/HMAppDelegate.m +++ b/KCD/HMAppDelegate.m @@ -8,6 +8,8 @@ #import "HMAppDelegate.h" +#import "KCD-Swift.h" + #import "HMUserDefaults.h" #import "HMBroserWindowController.h" #import "HMHistoryWindowController.h" @@ -25,7 +27,6 @@ #import "HMFleetManager.h" #import "HMPeriodicNotifier.h" -#import "HMHistoryItemCleaner.h" #import "HMTSVSupport.h" diff --git a/KCD/HMHistoryItemCleaner.h b/KCD/HMHistoryItemCleaner.h deleted file mode 100644 index 50e95aea..00000000 --- a/KCD/HMHistoryItemCleaner.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// HMHistoryItemCleaner.h -// KCD -// -// Created by Hori,Masaki on 2016/06/27. -// Copyright © 2016年 Hori,Masaki. All rights reserved. -// - -#import - -@interface HMHistoryItemCleaner : NSObject - -- (void)cleanOldHistoryItems; - -@end diff --git a/KCD/HMHistoryItemCleaner.m b/KCD/HMHistoryItemCleaner.m deleted file mode 100644 index 479d5a59..00000000 --- a/KCD/HMHistoryItemCleaner.m +++ /dev/null @@ -1,69 +0,0 @@ -// -// HMHistoryItemCleaner.m -// KCD -// -// Created by Hori,Masaki on 2016/06/27. -// Copyright © 2016年 Hori,Masaki. All rights reserved. -// - -#import "HMHistoryItemCleaner.h" - -#import "HMUserDefaults.h" - -#import "HMLocalDataStore.h" - - -@implementation HMHistoryItemCleaner - -- (void)cleanOldHistoryItems -{ - if(!HMStandardDefaults.cleanOldHistoryItems) return; - - HMLocalDataStore *store = [HMLocalDataStore oneTimeEditor]; - - NSDate *date = [NSDate dateWithTimeIntervalSinceNow:-1 * HMStandardDefaults.cleanSiceDays * 24 * 60 * 60]; - NSPredicate *p01 = [NSPredicate predicateWithFormat:@"date < %@", date]; - NSPredicate *p02 = [NSPredicate predicateWithFormat:@"mark = 0 || mark = nil"]; - NSPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[p01, p02]]; - - NSError *error = nil; - NSArray *array = [store objectsWithEntityName:@"KaihatuHistory" - predicate:predicate - error:&error]; - if(!error) { - for(NSManagedObject *obj in array) { - [store deleteObject:obj]; - } - } else { - NSLog(@"%s ERROR: KaihatuHistory, %@", __PRETTY_FUNCTION__, error); - } - - error = nil; - array = [store objectsWithEntityName:@"KenzoHistory" - predicate:predicate - error:&error]; - if(!error) { - for(NSManagedObject *obj in array) { - [store deleteObject:obj]; - } - } else { - NSLog(@"%s ERROR: KenzoHistory, %@", __PRETTY_FUNCTION__, error); - } - - NSArray *area = @[@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9"]; - NSPredicate *p03 = [NSPredicate predicateWithFormat:@"mapArea IN %@", area]; - predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[predicate, p03]]; - - error = nil; - array = [store objectsWithEntityName:@"DropShipHistory" - predicate:predicate - error:&error]; - if(!error) { - for(NSManagedObject *obj in array) { - [store deleteObject:obj]; - } - } else { - NSLog(@"%s ERROR: DropShipHistory, %@", __PRETTY_FUNCTION__, error); - } -} -@end diff --git a/KCD/HMHistoryItemCleaner.swift b/KCD/HMHistoryItemCleaner.swift new file mode 100644 index 00000000..65190c45 --- /dev/null +++ b/KCD/HMHistoryItemCleaner.swift @@ -0,0 +1,56 @@ +// +// HMHistoryItemCleaner.swift +// KCD +// +// Created by Hori,Masaki on 2016/12/18. +// Copyright © 2016年 Hori,Masaki. All rights reserved. +// + +import Cocoa + +class HMHistoryItemCleaner: NSObject { + func cleanOldHistoryItems() { + guard HMStandardDefaults.cleanOldHistoryItems else { + return + } + guard let store = HMLocalDataStore.oneTimeEditor() else { + return + } + + let date = Date(timeIntervalSinceNow: TimeInterval(-1 * HMStandardDefaults.cleanSiceDays * 24 * 60 * 60)) + let predicate01 = NSPredicate(format: "date < %@", argumentArray: [date]) + let predicate02 = NSPredicate(format: "mark = 0 || mark = nil") + let predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [predicate01, predicate02]) + do { + let kaihatuHistories = try store.objects(withEntityName: "KaihatuHistory", predicate: predicate) + for obj in kaihatuHistories { + store.delete(obj) + } + } catch (let error) { + print("ERROR: KaihatuHistory, \(error)") + return + } + + do { + let kenzoHistory = try store.objects(withEntityName: "KenzoHistory", predicate: predicate) + for obj in kenzoHistory { + store.delete(obj) + } + } catch (let error) { + print("ERROR: KenzoHistory, \(error)") + return + } + + let predicate03 = NSPredicate(format: "mapArea IN %@", argumentArray: [["1", "2", "3", "4", "5", "6", "7", "8", "9"]]) + let predicate04 = NSCompoundPredicate(andPredicateWithSubpredicates: [predicate, predicate03]) + do { + let dropHistories = try store.objects(withEntityName: "DropShipHistory", predicate: predicate04) + for obj in dropHistories { + store.delete(obj) + } + } catch (let error) { + print("ERROR: DropShipHistory, \(error)") + return + } + } +} diff --git a/KCD/KCD-Bridging-Header.h b/KCD/KCD-Bridging-Header.h new file mode 100644 index 00000000..58ffea3b --- /dev/null +++ b/KCD/KCD-Bridging-Header.h @@ -0,0 +1,9 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + +#import "HMUserDefaults.h" + + +#import "HMLocalDataStore.h" + -- 2.11.0