RHDynamicPropertyObject 1.0.0

RHDynamicPropertyObject 1.0.0

测试已测试
语言语言 Obj-CObjective C
许可证 BSD
发布最新发布2014年12月

Richard Heard维护。



  • Richard Heard

RHDynamicPropertyObject 可以让子类在运行时轻松提供属性的动态实现。

支持的属性类型

  • id
  • BOOL
  • int
  • long
  • unsigned long
  • long long
  • unsigned long long
  • double
  • float
  • NSInteger
  • NSUInteger

概述

通过实现方法 valueForDynamicProperty:setValue:forDynamicProperty:,您的子类可以轻松实现运行时声明为 @dynamic 的属性。这允许您使用 NSMutableDictionary 或其他形式的键/值存储来获取对象。例如,查看 RHSQLiteKit,其中 RHSQLiteObject 是 RHDynamicPropertyObject 的子类。

接口

@interface RHDynamicPropertyObject : NSObject

//subclassers should implement the below methods for supported property names
-(id)valueForDynamicProperty:(NSString*)propertyName;
-(void)setValue:(id)value forDynamicProperty:(NSString*)propertyName;

//you can override this method and return NO to prevent specific properties from being dynamically implemented. Default implementation just returns YES.
+(BOOL)shouldImplementDynamicProperty:(NSString*)propertyName;


//info
+(Class)classForProperty:(NSString*)propertyName; //assumes NSNumber for numeric types. structs etc return nil.

@end

许可证

在修改后的 BSD 许可证下发布。 (需要归属权)

RHDynamicPropertyObject

Copyright (c) 2013 Richard Heard. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Mac + iOS 版本支持

此代码已在 Mac OS 10.8+ 上进行了测试。它也应在 iOS 5+ 上运行良好。

如果遇到任何问题,或者您认为可以改进的地方,请随时提交问题。

RHDynamicPropertyObject 使用 ARC。

感谢

如果您觉得这个项目很有用,下次见到我时请买我一杯啤酒,或者从我的 愿望列表 购物。