From ca5c545f8987055318d5a33f1f44fcd68958b64b Mon Sep 17 00:00:00 2001 From: masakih Date: Thu, 2 Feb 2017 23:34:37 +0900 Subject: [PATCH] =?utf8?q?HMKCManagedObject=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 | 10 ++-- KCD/HMKCManagedObject.h | 13 ---- KCD/HMKCManagedObject.m | 86 --------------------------- KCD/HMKCManagedObject.swift | 64 ++++++++++++++++++++ KCD/KCD-Bridging-Header.h | 1 - KCD/KCD.xcdatamodeld/KCD.xcdatamodel/contents | 6 +- 6 files changed, 71 insertions(+), 109 deletions(-) delete mode 100644 KCD/HMKCManagedObject.h delete mode 100644 KCD/HMKCManagedObject.m create mode 100644 KCD/HMKCManagedObject.swift diff --git a/KCD.xcodeproj/project.pbxproj b/KCD.xcodeproj/project.pbxproj index 765fab5e..3a722c88 100644 --- a/KCD.xcodeproj/project.pbxproj +++ b/KCD.xcodeproj/project.pbxproj @@ -265,7 +265,6 @@ F4D05BDB1E0F76A800688D66 /* HMResourceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4D05BDA1E0F76A800688D66 /* HMResourceViewController.swift */; }; F4D05BDF1E0F8B6900688D66 /* HMPowerUpSupportViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4D05BDE1E0F8B6900688D66 /* HMPowerUpSupportViewController.swift */; }; F4D05BE11E0FAB8E00688D66 /* HMShipViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4D05BE01E0FAB8E00688D66 /* HMShipViewController.swift */; }; - F4D2CBC818B0555A000EBC59 /* HMKCManagedObject.m in Sources */ = {isa = PBXBuildFile; fileRef = F4D2CBC718B0555A000EBC59 /* HMKCManagedObject.m */; }; F4E5FF021E150A850026868C /* HMAncherageRepairTimerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4E5FF011E150A850026868C /* HMAncherageRepairTimerViewController.swift */; }; F4E5FF041E1518200026868C /* HMScreenshotDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4E5FF031E1518200026868C /* HMScreenshotDetailViewController.swift */; }; F4E5FF061E1523900026868C /* HMScreenshotCollectionViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4E5FF051E1523900026868C /* HMScreenshotCollectionViewItem.swift */; }; @@ -285,6 +284,7 @@ F4F9471F1D5DBBC700F95998 /* HMRepairListViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4F947211D5DBBC700F95998 /* HMRepairListViewController.xib */; }; F4F947281D5DBC5500F95998 /* HMAncherageRepairTimerViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4F9472A1D5DBC5500F95998 /* HMAncherageRepairTimerViewController.xib */; }; F4FC3E8C1E43660400E41228 /* HMKCGuardEscaped.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FC3E8B1E43660400E41228 /* HMKCGuardEscaped.swift */; }; + F4FC3E8E1E4368BB00E41228 /* HMKCManagedObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FC3E8D1E4368BB00E41228 /* HMKCManagedObject.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -574,8 +574,6 @@ F4D05BDA1E0F76A800688D66 /* HMResourceViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMResourceViewController.swift; sourceTree = ""; }; F4D05BDE1E0F8B6900688D66 /* HMPowerUpSupportViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMPowerUpSupportViewController.swift; sourceTree = ""; }; F4D05BE01E0FAB8E00688D66 /* HMShipViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMShipViewController.swift; sourceTree = ""; }; - F4D2CBC618B0555A000EBC59 /* HMKCManagedObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMKCManagedObject.h; sourceTree = ""; }; - F4D2CBC718B0555A000EBC59 /* HMKCManagedObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMKCManagedObject.m; sourceTree = ""; }; F4D6BC4C1A923C0B00742FEB /* LocalData 2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "LocalData 2.xcdatamodel"; sourceTree = ""; }; F4E5FF011E150A850026868C /* HMAncherageRepairTimerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMAncherageRepairTimerViewController.swift; sourceTree = ""; }; F4E5FF031E1518200026868C /* HMScreenshotDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMScreenshotDetailViewController.swift; sourceTree = ""; }; @@ -629,6 +627,7 @@ F4F947331D5EB44700F95998 /* zh-Hant-TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant-TW"; path = "zh-Hant-TW.lproj/HMBroserWindowController.strings"; sourceTree = ""; }; F4F947351D5EBDD700F95998 /* zh-Hant-TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant-TW"; path = "zh-Hant-TW.lproj/HMShipViewController.strings"; sourceTree = ""; }; F4FC3E8B1E43660400E41228 /* HMKCGuardEscaped.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMKCGuardEscaped.swift; sourceTree = ""; }; + F4FC3E8D1E4368BB00E41228 /* HMKCManagedObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMKCManagedObject.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -964,8 +963,7 @@ children = ( F4513EDB18B619B600073552 /* HMCoreDataManager.h */, F4513EDC18B619B600073552 /* HMCoreDataManager.m */, - F4D2CBC618B0555A000EBC59 /* HMKCManagedObject.h */, - F4D2CBC718B0555A000EBC59 /* HMKCManagedObject.m */, + F4FC3E8D1E4368BB00E41228 /* HMKCManagedObject.swift */, F4F9F8911C6BA26400D0EE76 /* KCD */, F4F9F8921C6BA28200D0EE76 /* Local */, F4F9F8931C6BA29500D0EE76 /* Temporary */, @@ -1597,11 +1595,11 @@ F49097851E1A15AF0085A45D /* HMSlotItemLevelView.swift in Sources */, F44BC6C31E221865004644E3 /* HMAirCorpsSupplyCommand.swift in Sources */, F44BC72D1E2A0AA0004644E3 /* HMMasterMapAreaCommand.swift in Sources */, - F4D2CBC818B0555A000EBC59 /* HMKCManagedObject.m in Sources */, F44BC6D51E226308004644E3 /* HMNyukyoSpeedChangeCommand.swift in Sources */, F4AA59361E1D36C5001667AF /* HMQuestProgressTransformer.swift in Sources */, F44BC72F1E2A0B75004644E3 /* HMMaserShipCommand.swift in Sources */, F44BC7271E29ED87004644E3 /* HMMasterUseItemCommand.swift in Sources */, + F4FC3E8E1E4368BB00E41228 /* HMKCManagedObject.swift in Sources */, F4A0D7171E2FB7E000224DCE /* HMCompositCommand.swift in Sources */, F44BC7011E251408004644E3 /* HMDestroyItem2Command.swift in Sources */, F45FBB731E116F53000E72B9 /* HMMainTabVIewItemViewController.swift in Sources */, diff --git a/KCD/HMKCManagedObject.h b/KCD/HMKCManagedObject.h deleted file mode 100644 index 135429cb..00000000 --- a/KCD/HMKCManagedObject.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// HMKCManagedObject.h -// KCD -// -// Created by Hori,Masaki on 2014/02/16. -// Copyright (c) 2014年 Hori,Masaki. All rights reserved. -// - -#import - -@interface HMKCManagedObject : NSManagedObject - -@end diff --git a/KCD/HMKCManagedObject.m b/KCD/HMKCManagedObject.m deleted file mode 100644 index eca06175..00000000 --- a/KCD/HMKCManagedObject.m +++ /dev/null @@ -1,86 +0,0 @@ -// -// HMKCManagedObject.m -// KCD -// -// Created by Hori,Masaki on 2014/02/16. -// Copyright (c) 2014年 Hori,Masaki. All rights reserved. -// - -#import "HMKCManagedObject.h" - -#import "KCD-Swift.h" - - -@implementation HMKCManagedObject - - -- (BOOL)validateValue:(inout id *)ioValue forKey:(NSString *)inKey error:(out NSError **)outError -{ - - NSArray *t = @[@"api_enqflg", @"api_aftershipid", @"api_progress", - @"api_usebull", -// @"api_next_rate_0", @"api_next_rate_1", @"api_next_rate_2", -// @"api_req_shiptype_0", @"api_req_shiptype_1", @"api_req_shiptype_2", @"api_req_shiptype_3", @"api_req_shiptype_4", @"api_req_shiptype_5", -// @"api_next_rate_req_0", @"api_next_rate_req_1", @"api_next_rate_req_2", -// @"api_link_no_0", @"api_link_no_1", - @"api_flagship", @"api_name_id", - @"api_comment_id", @"api_nickname_id", @"api_member_id", - @"api_flag_0", @"api_flag_1", @"api_flag_2", @"api_flag_3", @"api_flag_4", - @"api_flag_5", @"api_flag_6", @"api_flag_7", - @"api_level"]; - if([t containsObject:inKey]) { - if(![*ioValue isKindOfClass:[NSNumber class]]) { - id newValue = @([*ioValue integerValue]); - if(newValue) { - *ioValue = newValue; - return YES; - } - return NO; - } - } - if([*ioValue isKindOfClass:[NSNull class]]) { - *ioValue = nil; - return YES; - } - - return YES; -} - -- (id)valueForUndefinedKey:(NSString *)key -{ - if([key isEqualToString:@"description"]) { - return [self valueForKey:@"description_"]; - } - if([key hasPrefix:@"api_"]) { - return [self valueForKey:[key substringFromIndex:4]]; - } - - NSEntityDescription *entity = [self entity]; - NSLog(@"Entity %@ dose not have key %@", entity.name, key); - return nil; - -// return [super valueForUndefinedKey:key]; -} - -- (void)setValue:(id)value forUndefinedKey:(NSString *)key -{ - if([key hasPrefix:@"api_"]) { - if([key length] < 5) { - NSLog(@"????"); - return; - } - [self setValue:value forKey:[key substringFromIndex:4]]; - return; - } - if([key isEqualToString:@"description"]) { - [self setValue:value forKey:@"description_"]; - return; - } - - NSEntityDescription *entity = [self entity]; - NSLog(@"Entity %@ dose not have key %@, value class is %@, value is '%@'", entity.name, key, NSStringFromClass([value class]), value); -// return; -// [super setValue:value forUndefinedKey:key]; -} - -@end diff --git a/KCD/HMKCManagedObject.swift b/KCD/HMKCManagedObject.swift new file mode 100644 index 00000000..e7292526 --- /dev/null +++ b/KCD/HMKCManagedObject.swift @@ -0,0 +1,64 @@ +// +// HMKCManagedObject.swift +// KCD +// +// Created by Hori,Masaki on 2017/02/02. +// Copyright © 2017年 Hori,Masaki. All rights reserved. +// + +import Foundation + +enum HMKCManagedObjectError: Error { + case invalid +} + +class HMKCManagedObject: NSManagedObject { + static let intValueKyes: [String] = + [ + "api_enqflg", "api_aftershipid", "api_progress", "api_usebull", + "api_flagship", "api_name_id", + "api_comment_id", "api_nickname_id", "api_member_id", + "api_flag_0", "api_flag_1", "api_flag_2", "api_flag_3", "api_flag_4", + "api_flag_5", "api_flag_6", "api_flag_7", + "api_level" + ] + override func validateValue(_ value: AutoreleasingUnsafeMutablePointer, forKey key: String) throws { + if value.pointee is NSNull { + value.pointee = nil + return + } + if HMKCManagedObject.intValueKyes.contains(key) { + if let _ = value.pointee as? Int { return } + if let s = value.pointee as? String { + value.pointee = Int(s) as AnyObject? + return + } + print("HMKCManagedObject type \(type(of: value.pointee))") + throw HMKCManagedObjectError.invalid + } + } + + override func value(forUndefinedKey key: String) -> Any? { + if key == "description" { return value(forKey: "description_") } + if key.hasPrefix("api_") { + let four = key.index(key.startIndex, offsetBy: 4) + let k = key[four.. - + @@ -104,7 +104,7 @@ - + @@ -242,7 +242,7 @@ - + -- 2.11.0