OSDN Git Service

HMMasterMissionCommandクラスをSwiftで書き換え
[kcd/KCD.git] / KCD / HMKCManagedObject.m
1 //
2 //  HMKCManagedObject.m
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2014/02/16.
6 //  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
7 //
8
9 #import "HMKCManagedObject.h"
10
11 #import "HMJSONCommand.h"
12
13
14 @implementation HMKCManagedObject
15
16
17 - (BOOL)validateValue:(inout id *)ioValue forKey:(NSString *)inKey error:(out NSError **)outError
18 {
19         
20         NSArray *t = @[@"api_enqflg", @"api_aftershipid", @"api_progress",
21                                    @"api_usebull",
22 //                                 @"api_next_rate_0", @"api_next_rate_1", @"api_next_rate_2",
23 //                                 @"api_req_shiptype_0", @"api_req_shiptype_1", @"api_req_shiptype_2", @"api_req_shiptype_3", @"api_req_shiptype_4", @"api_req_shiptype_5",
24 //                                 @"api_next_rate_req_0", @"api_next_rate_req_1", @"api_next_rate_req_2",
25 //                                 @"api_link_no_0", @"api_link_no_1",
26                                    @"api_flagship", @"api_name_id",
27                                    @"api_comment_id", @"api_nickname_id", @"api_member_id",
28                                    @"api_flag_0", @"api_flag_1", @"api_flag_2", @"api_flag_3", @"api_flag_4",
29                                    @"api_flag_5", @"api_flag_6", @"api_flag_7",
30                                    @"api_level"];
31         if([t containsObject:inKey]) {
32                 if(![*ioValue isKindOfClass:[NSNumber class]]) {
33                         id newValue = @([*ioValue integerValue]);
34                         if(newValue) {
35                                 *ioValue = newValue;
36                                 return YES;
37                         }
38                         return NO;
39                 }
40         }
41         if([*ioValue isKindOfClass:[NSNull class]]) {
42                 *ioValue = nil;
43                 return YES;
44         }
45         
46         return YES;
47 }
48
49 - (id)valueForUndefinedKey:(NSString *)key
50 {
51         if([key isEqualToString:@"description"]) {
52                 return [self valueForKey:@"description_"];
53         }
54         if([key hasPrefix:@"api_"]) {
55                 return [self valueForKey:keyByDeletingPrefix(key)];
56         }
57         
58         NSEntityDescription *entity = [self entity];
59         NSLog(@"Entity %@ dose not have key %@", entity.name, key);
60         return nil;
61         
62 //      return [super valueForUndefinedKey:key];
63 }
64
65 - (void)setValue:(id)value forUndefinedKey:(NSString *)key
66 {
67         if([key hasPrefix:@"api_"]) {
68                 if([key length] < 5) {
69                         NSLog(@"????");
70                         return;
71                 }
72                 [self setValue:value forKey:keyByDeletingPrefix(key)];
73                 return;
74         }
75         if([key isEqualToString:@"description"]) {
76                 [self setValue:value forKey:@"description_"];
77                 return;
78         }
79         
80         NSEntityDescription *entity = [self entity];
81         NSLog(@"Entity %@ dose not have key %@, value class is %@, value is '%@'", entity.name, key, NSStringFromClass([value class]), value);
82 //      return;
83 //      [super setValue:value forUndefinedKey:key];
84 }
85
86 @end