通过model 得到 属性名和属性类型 放进数据库

该博客介绍了一个Objective-C方法,用于从模型中获取属性名称和类型,并将它们存储到SQLite数据库。首先,使用`objc/runtime.h`获取模型的属性列表,然后根据属性类型创建不同的查询操作(如插入、更新和删除)。在`selectALWithModel:`方法中,从数据库中检索数据并根据属性设置模型对象。
摘要由CSDN通过智能技术生成


#import <objc/runtime.h>


typedef NS_ENUM(NSUInteger, PropertyArrayType) {

    PropertyArrayTypeName,

    PropertyArrayTypeAttribute

};



+ (NSMutableArray *)arrayWithModel:(id)model

                              type:(PropertyArrayType)type{

    

    Class clazz = [model class];

    u_int count;

    

    objc_property_t* properties = class_copyPropertyList(clazz, &count);

    NSMutableArray* propertyArray = [NSMutableArray arrayWithCapacity:count];

    NSMutableArray* attributeArray = [NSMutableArray arrayWithCapacity:count];

    for (int i = 0; i < count ; i++)

    {

        objc_property_t prop= properties[i];

        const char* propertyName = property_getName(prop);

        const char* attributeName = property_getAttributes(prop);

        

        [attributeArray addObject:[NSString stringWithCString:attributeName encoding:NSUT

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值