OSDN Git Service

HMKCManagedObjectをSwiftに変換した
authormasakih <masakih@users.sourceforge.jp>
Thu, 2 Feb 2017 14:34:37 +0000 (23:34 +0900)
committermasakih <masakih@users.sourceforge.jp>
Thu, 2 Feb 2017 14:34:37 +0000 (23:34 +0900)
KCD.xcodeproj/project.pbxproj
KCD/HMKCManagedObject.h [deleted file]
KCD/HMKCManagedObject.m [deleted file]
KCD/HMKCManagedObject.swift [new file with mode: 0644]
KCD/KCD-Bridging-Header.h
KCD/KCD.xcdatamodeld/KCD.xcdatamodel/contents

index 765fab5..3a722c8 100644 (file)
                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 */; };
                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 */
                F4D05BDA1E0F76A800688D66 /* HMResourceViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMResourceViewController.swift; sourceTree = "<group>"; };
                F4D05BDE1E0F8B6900688D66 /* HMPowerUpSupportViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMPowerUpSupportViewController.swift; sourceTree = "<group>"; };
                F4D05BE01E0FAB8E00688D66 /* HMShipViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMShipViewController.swift; sourceTree = "<group>"; };
-               F4D2CBC618B0555A000EBC59 /* HMKCManagedObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMKCManagedObject.h; sourceTree = "<group>"; };
-               F4D2CBC718B0555A000EBC59 /* HMKCManagedObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMKCManagedObject.m; sourceTree = "<group>"; };
                F4D6BC4C1A923C0B00742FEB /* LocalData 2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "LocalData 2.xcdatamodel"; sourceTree = "<group>"; };
                F4E5FF011E150A850026868C /* HMAncherageRepairTimerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMAncherageRepairTimerViewController.swift; sourceTree = "<group>"; };
                F4E5FF031E1518200026868C /* HMScreenshotDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMScreenshotDetailViewController.swift; sourceTree = "<group>"; };
                F4F947331D5EB44700F95998 /* zh-Hant-TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant-TW"; path = "zh-Hant-TW.lproj/HMBroserWindowController.strings"; sourceTree = "<group>"; };
                F4F947351D5EBDD700F95998 /* zh-Hant-TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant-TW"; path = "zh-Hant-TW.lproj/HMShipViewController.strings"; sourceTree = "<group>"; };
                F4FC3E8B1E43660400E41228 /* HMKCGuardEscaped.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMKCGuardEscaped.swift; sourceTree = "<group>"; };
+               F4FC3E8D1E4368BB00E41228 /* HMKCManagedObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMKCManagedObject.swift; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
                        children = (
                                F4513EDB18B619B600073552 /* HMCoreDataManager.h */,
                                F4513EDC18B619B600073552 /* HMCoreDataManager.m */,
-                               F4D2CBC618B0555A000EBC59 /* HMKCManagedObject.h */,
-                               F4D2CBC718B0555A000EBC59 /* HMKCManagedObject.m */,
+                               F4FC3E8D1E4368BB00E41228 /* HMKCManagedObject.swift */,
                                F4F9F8911C6BA26400D0EE76 /* KCD */,
                                F4F9F8921C6BA28200D0EE76 /* Local */,
                                F4F9F8931C6BA29500D0EE76 /* Temporary */,
                                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 (file)
index 135429c..0000000
+++ /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 <CoreData/CoreData.h>
-
-@interface HMKCManagedObject : NSManagedObject
-
-@end
diff --git a/KCD/HMKCManagedObject.m b/KCD/HMKCManagedObject.m
deleted file mode 100644 (file)
index eca0617..0000000
+++ /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 (file)
index 0000000..e729252
--- /dev/null
@@ -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<AnyObject?>, 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..<key.endIndex]
+            return value(forKey: k)
+        }
+        print("Entity \(entity.name) dose not have key \(key)")
+        return nil
+    }
+    override func setValue(_ value: Any?, forUndefinedKey key: String) {
+        if key == "description" {
+            setValue(value, forKey: "description_")
+            return
+        }
+        if key.hasPrefix("api_") {
+            let four = key.index(key.startIndex, offsetBy: 4)
+            let k = key[four..<key.endIndex]
+            setValue(value, forKey: k)
+            return
+        }
+        print("Entity \(entity.name) dose not have key \(key)")
+    }
+}
index b92acbd..e4e3624 100644 (file)
@@ -9,7 +9,6 @@
 
 // Core Data
 #import "HMCoreDataManager.h"
-#import "HMKCManagedObject.h"
 
 //
 #import "TemporaryEnumDefined.h"
index 493e0c8..1eb0984 100644 (file)
@@ -89,7 +89,7 @@
         <attribute name="member_id" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
         <attribute name="state" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
     </entity>
-    <entity name="MasterFurniture" representedClassName="HMKCManagedObject" syncable="YES">
+    <entity name="MasterFurniture" representedClassName="KCD.HMKCManagedObject" syncable="YES">
         <attribute name="description_" optional="YES" attributeType="String" syncable="YES"/>
         <attribute name="id" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" indexed="YES" syncable="YES"/>
         <attribute name="no" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
         <attribute name="name" attributeType="String" syncable="YES"/>
         <attribute name="type" optional="YES" attributeType="Integer 64" usesScalarValueType="NO" syncable="YES"/>
     </entity>
-    <entity name="MasterMapCell" representedClassName="HMKCManagedObject" syncable="YES">
+    <entity name="MasterMapCell" representedClassName="KCD.HMKCManagedObject" syncable="YES">
         <attribute name="color_no" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
         <attribute name="id" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
         <attribute name="map_no" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
         <attribute name="sortno" attributeType="Integer 64" usesScalarValueType="NO" indexed="YES" syncable="YES"/>
         <relationship name="ships" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="MasterShip" inverseName="stype" inverseEntity="MasterShip" syncable="YES"/>
     </entity>
-    <entity name="MasterUseItem" representedClassName="HMKCManagedObject" syncable="YES">
+    <entity name="MasterUseItem" representedClassName="KCD.HMKCManagedObject" syncable="YES">
         <attribute name="category" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
         <attribute name="description_0" optional="YES" attributeType="String" syncable="YES"/>
         <attribute name="description_1" optional="YES" attributeType="String" syncable="YES"/>