编码是一项重复性工作,程序员应遵循“不要重复自己”(Don't Repeat Yourself)原则,避免重复代码。
我还有很多要学习的东西,但经验和实践在与其他社区成员分享时更有价值,这就是我创建 RPOFoundation 的原因。
这是一个小的库,其中包含一些分类和辅助工具,用于编写更少的代码和更多的单行代码。如果您认为它适合您的其中一个项目,或者 您可以添加代码来帮助我改进它。
到目前为止,RPOFoundation 包含以下类
NSLog 的宏简写
DLog(@"This is a log with the number %d", 7);
将在 DEBUG 中记录此内容,在 RELEASE 中不做任何事情
-[ClassName methodName:](0x7fda90f0a520) This is a log with the number 7
一个名为 thisIsAniPad
的宏参数,如果正在 iPad 上运行则返回 YES,在其他情况下返回 NO。
一个使用一些额外方法进行的分类
+ (UIColor *)colorWithRGB:(NSString *) rgbColor;
+ (UIColor *)colorWithRGB:(NSString *) rgbColor alpha:(float) alpha;
一个使用一些额外方法进行的分类
-(BOOL)isNavigationController;
-(void)removeBackButtonText;
-(UIViewController *)pushToStoryboardNamed:(NSString *) storyboardName
withViewIdentifier:(NSString *) viewIdentifier
returningViewController:(nextViewControllerBlock) block;
-(UIViewController *)presentStoryboardNamed:(NSString *) storyboardName
withViewIdentifier:(NSString *) viewIdentifier
returningViewController:(nextViewControllerBlock) block;
基于 Maquert 的 Sauron 项目 的屏幕切换辅助工具。
用于最常见和简单的 Code Data 操作的辅助工具。
+ (id) queryOneObjectWithEntityName:(NSString *)entityName
predicate:(NSPredicate *)predicate
sortDescriptors:(NSArray *)sortDescriptors
context:(NSManagedObjectContext *)context;
+ (id) queryOneObjectWithEntityName:(NSString *)entityName
predicate:(NSPredicate *)predicate
context:(NSManagedObjectContext *)context;
+ (NSArray *) queryObjectsWithEntityName:(NSString *)entityName
predicate:(NSPredicate *)predicate
context:(NSManagedObjectContext *)context;
+ (NSArray *) queryObjectsWithEntityName:(NSString *)entityName
predicate:(NSPredicate *)predicate
sortDescriptors:(NSArray *)sortDescriptors
context:(NSManagedObjectContext *)context;
+ (void)deleteAllObjectsWithEntityName:(NSString *)name inContext:(NSManagedObjectContext *)moc;
+ (void)deleteAllObjectsWithEntityNames:(NSArray *)names inContext:(NSManagedObjectContext *)moc;
+ (void)deleteAllObjectsWithEntities:(NSArray *)entities inContext:(NSManagedObjectContext *)moc;
+ (void)deleteAllObjectsWithEntityName:(NSString *)name predicate:(NSPredicate *)predicate inContext:(NSManagedObjectContext *)moc;
+ (void)deleteAllObjectsWithEntityNames:(NSArray *)names predicate:(NSPredicate *)predicate inContext:(NSManagedObjectContext *)moc;
+ (void)deleteAllObjectsWithEntities:(NSArray *)entities predicate:(NSPredicate *)predicate inContext:(NSManagedObjectContext *)moc;
+ (BOOL)saveContext:(NSManagedObjectContext *)moc;
+ (BOOL)saveContext:(NSManagedObjectContext *)moc error:(NSError *)error;
+ (NSManagedObjectContext *)newMOCWithParent:(NSManagedObjectContext *)parentMoc;
要运行示例项目,请克隆仓库,并首先从示例目录运行 pod install
RPOFoundation 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "RPOFoundation"
Roberto Pastor, [email protected]
RPOFoundation遵循MIT许可证。更多信息请参阅LICENSE文件。