AngerDragon / lib-obj-c-attr

Attributes for your code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status License Platform

#libObjCAttr - attributes for your code

libObjCAttr is attribute-oriented programming for Objective-C language. It is compile-time based with the support of Xcode auto-completion and errors tracing features. We nailed every aspect of the implementation including performance, so attributes will never be a bottleneck.

Our solution helps reduce the complexity of code, makes it compact and self-documented. There are a lot of languages with attributes support, we added Objective-C into that list.

##Installation

CocoaPods is the only recommended way of libObjCAttr integration. Besides standard configuration of pod dependencies pod_install hook definition required as shown below. A typical Podfile will look as follows:

pod 'libObjCAttr'

post_install do |installer|
    require File.expand_path('ROADConfigurator.rb', './Pods/libObjCAttr/libObjCAttr/Resources/')
    ROADConfigurator::post_install(installer)
end

##Samples

It is super easy to mark your code with an attribute. We currently support 4 types of attributes:

  • Class attributes
  • IVar attributes
  • Method attributes
  • Property attributes

Check out this example to get to know how to declare them:

RF_ATTRIBUTE(MyAttribute, stringProperty = @"Hello world")
@interface AnnotatedClass : NSObject {

    RF_ATTRIBUTE(MyAttribute, numericProperty = @9000)
    NSObject * _someField;
}

RF_ATTRIBUTE(MyAttribute, blockProperty = ^(int value) { return value; })
- (void)foo;

RF_ATTRIBUTE(MyAttribute, objectProperty = [NSObject new])
@property NSString *name;

@end

An attribute can be any class inherited from the NSObject or its subclasses. It may or may not have properties.

#import <ROAD/ROADAttribute.h>

@interface MyAttribute : NSObject

@property NSString *stringProperty;
@property NSNumber *numericProperty;
@property (copy) id blockProperty;
@property id objectProperty;

@end

Now you can get them in runtime with code like this:

...

NSArray *classAttributes = [AnnotatedClass RF_attributesForClass];
NSArray *ivarAttributes = [AnnotatedClass RF_attributesForIvar:@"_someField"];

// Let's filter it, in case there are many of them
MyAttribute *methodAttributes = [AnnotatedClass RF_attributeForMethod:@"foo" withAttributeType:[MyAttribute class]];
MyAttribute *classAttributes = [AnnotatedClass RF_attributeForProperty:@"name" withAttributeType:[MyAttribute class]];

...

##Requirements libObjCAttr requires iOS 5.0 and above. The compatibility with 4.3 and older is not tested.

libObjCAttr was initially designed to use ARC.

##Solutions powerd by LibObjCAttr

##Contact Follow LibObjCAttr on Twitter (@LibObjCAttr)

##License libObjCAttr is made available under the terms of the BSD-3. See the LICENSE file that accompanies this distribution for the full text of the license.

About

Attributes for your code

License:Other