Skip to content

Commit 79370fb

Browse files
author
ChrisCai
committed
解决实现代理方法不起作用的Bug,在模型中遵守协议,实现代理方法可以自定义哪些属性不需要保存到数据库
1 parent e401b44 commit 79370fb

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

GKDatabase/Demo/models/Student.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
//
88

99
#import <UIKit/UIKit.h>
10-
@interface Student : NSObject
10+
#import "GKDatabase.h"
11+
@interface Student : NSObject<GKObjcPropertyDelegate>
1112
@property(nonatomic, copy) NSString *name;
1213
@property(nonatomic, assign) NSInteger age;
1314
@property(nonatomic, assign) CGFloat score;
1415
@property(nonatomic, strong) NSArray *books;
16+
- (NSArray *)notSaveToDatabaseFormAttributesList;
1517
@end

GKDatabase/Demo/models/Student.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
#import "Student.h"
1010

1111
@implementation Student
12-
12+
/// 不存入数据库
13+
- (NSArray *)notSaveToDatabaseFormAttributesList{
14+
return @[@"score"];
15+
}
1316
@end

GKDatabase/GKDatabase/GKObjcProperty.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
@interface GKObjcProperty : NSObject
2626

2727
@property (nonatomic,strong) id<GKObjcPropertyDelegate> delegate;
28+
+ (GKObjcProperty *)getObject;
2829

2930
/**
3031
* 获取属性名列表 例 name

GKDatabase/GKDatabase/GKObjcProperty.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ + (GKObjcProperty *)getObject {
3333
* @return 属性类型列表
3434
*/
3535
+ (NSArray *)getUserNeedOCPropertyTypeListWithClass:(id)className {
36+
3637
if (className) {
37-
[self getObject].delegate = className;
38+
[self getObject].delegate = [[[className class] alloc]init];
3839
if ([[self getObject].delegate respondsToSelector:@selector(notSaveToDatabaseFormAttributesList)]) {
3940

4041
NSArray *userNeedAttributeList = [self getUserNeedAttributeListWithClass:className];
@@ -55,7 +56,6 @@ + (NSArray *)getUserNeedOCPropertyTypeListWithClass:(id)className {
5556
NSString *name = [NSString stringWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
5657
// 转换为Objective C 字符串
5758
NSString *type = [NSString stringWithCString:property_getAttributes(property) encoding:NSUTF8StringEncoding];
58-
5959
if ([name isEqualToString:userNeedAttribute]) {
6060
[tempArrayM addObject:[self getAttributesWith:type]];
6161
}
@@ -116,7 +116,7 @@ + (NSArray *)getSQLPropertyTypeListWithClass:(id)className {
116116
/// 获取属性名列表
117117
+ (NSArray *)getUserNeedAttributeListWithClass:(id)className {
118118
if (className) {
119-
[self getObject].delegate = className;
119+
[self getObject].delegate = [[[className class]alloc]init];
120120
if ([[self getObject].delegate respondsToSelector:@selector(notSaveToDatabaseFormAttributesList)]) {
121121

122122
NSArray *arr = [[self getObject].delegate notSaveToDatabaseFormAttributesList];

0 commit comments

Comments
 (0)