Skip to content

Commit

Permalink
类型问题
Browse files Browse the repository at this point in the history
  • Loading branch information
魏景云 committed Nov 30, 2016
1 parent 0adbc0d commit 7310834
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
@property (nonatomic, copy) NSString *longlongText;

// 年级下的所有班级
@property (nonatomic, strong) NSMutableArray<JYClassInfo *> *allClass;
@property (nonatomic, strong) NSArray<JYClassInfo *> *allClass;

@end
15 changes: 4 additions & 11 deletions JYDatabase - OC/JYDatabase - OC/JYDatabase/JYContentTable.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,6 @@ - (BOOL)jSONSerializationForType:(NSString *)type{
return abool;
}

- (BOOL)isArrayForAttributeName:(NSString *)aKey{
NSString *type = [self attributeTypeDic][aKey];
NSArray *array = @[@"T@\"NSMutableArray\"",@"T@\"NSArray\""];
__block BOOL abool= NO;
[array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
abool =abool || [obj isEqualToString:type];
}];
return abool;
}

// 特殊字段需要插入其它表
- (void)insertSpecialFieldDB:(FMDatabase *)aDB content:(id)aContent forKey:(NSString *)akey{

Expand Down Expand Up @@ -238,7 +228,10 @@ - (void)getSpecialFieldDB:(FMDatabase *)aDB content:(id)aContent forKey:(NSStrin
make.field(viceKey).equalTo(contentIdValue).asc(sort);
}];

if ([self isArrayForAttributeName:akey]) {
NSString *type = [self attributeTypeDic][akey];
if ([type isEqualToString:@"T@\"NSMutableArray\""]) {
[aContent setValue:[specialFieldValue mutableCopy] forKey:akey];
}else if ([type isEqualToString:@"T@\"NSArray\""]){
[aContent setValue:specialFieldValue forKey:akey];
}else{
NSAssert(specialFieldValue.count < 2,@"%@ 所包含的 %@ 字段对应表%@ 数据异常,该字段查询出来应该只有一个值现在出现了多个值,代码删除,插入可能有问题",self,akey,table);
Expand Down
7 changes: 5 additions & 2 deletions JYDatabase - OC/JYDatabase - OCTests/JYContentTableTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ - (JYGradeInfo *)getGradeInfo{
gradeInfo.gradeID = [NSString stringWithFormat:@"%f",[NSDate date].timeIntervalSince1970];
gradeInfo.gradeName = @"gradeName";
gradeInfo.longlongText = @"安拉说萨达斯大使鲁大师解答索朗多吉阿斯利康多久啊索朗多吉啊索朗多吉撒了肯德基卢萨卡的就阿斯利康大家阿拉山口大家卢萨卡的家啊索朗多吉啊索朗多吉萨里看到卢卡斯家里打扫家里的空间啊算了撒进来看到就撒了肯德基拉萨卡就收到啦升级到了撒娇的拉萨觉得萨鲁大师萨的旅客撒娇的拉萨金德拉克撒大家拉萨大家卢萨卡大家啦可是大家啊索朗多吉啊上课绝对拉升阶段拉萨肯德基卢萨卡就到拉萨肯德基拉萨肯德基拉萨的就撒了点酒洒了肯德基拉萨肯德基拉萨到拉萨的教练萨大家撒了点结束啦大家拉萨大家拉萨短裤收到了撒娇第六十九阿拉丁就撒了点酒撒了点酒洒落到家啦时间的撒了空间的拉萨到了撒娇的理解啊圣诞节啊圣诞节啊时间都撒到家啦圣诞节阿斯利康大家撒了肯德基撒了肯德基啊索朗多吉撒了点酒撒";
gradeInfo.allClass = [[NSMutableArray alloc] init];
NSMutableArray *arrayM = [[NSMutableArray alloc] init];
for (int i = 0 ; i < 10; i ++) {
JYClassInfo *classInfo = [self getClassInfoForGradeID:gradeInfo.gradeID];
[gradeInfo.allClass addObject:classInfo];
[arrayM addObject:classInfo];
}
gradeInfo.allClass = [arrayM copy];
return gradeInfo;
}

Expand Down Expand Up @@ -118,6 +119,7 @@ - (BOOL)gradeInfo:(JYGradeInfo *)gradeInfo1 equalTo:(JYGradeInfo *)gradeInfo2{
__block BOOL isEqual = YES;
NSArray<NSString *>*keys = @[@"gradeID",@"gradeName",@"longlongText"];
isEqual &= [self mode:gradeInfo1 equalTo:gradeInfo2 forKeys:keys];
XCTAssert([gradeInfo2.allClass isKindOfClass:[NSArray class]] && ![gradeInfo2.allClass isKindOfClass:[NSMutableArray class]]);
[gradeInfo1.allClass enumerateObjectsUsingBlock:^(JYClassInfo * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
isEqual &= [self classInfo:obj equalTo:gradeInfo2.allClass[idx]];
}];
Expand All @@ -132,6 +134,7 @@ - (BOOL)classInfo:(JYClassInfo *)classInfo1 equalTo:(JYClassInfo *)classInfo2{
NSArray<NSString *>*keys = @[@"classID",@"gradeID",@"className"];
isEqual &= [self mode:classInfo1 equalTo:classInfo2 forKeys:keys];
isEqual &= [self personInfo:classInfo1.teacher equalTo:classInfo2.teacher];
XCTAssert([classInfo2.students isKindOfClass:[NSMutableArray class]]);
[classInfo1.students enumerateObjectsUsingBlock:^(JYPersonInfo * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
isEqual &= [self personInfo:obj equalTo:classInfo2.students[idx]];
}];
Expand Down

0 comments on commit 7310834

Please sign in to comment.