Git Product home page Git Product logo

lib-obj-c-attr's Introduction

License Platform Version Coverage Status Build Status

#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 is 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 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]];

...

Also check out an info about an attribute generator, that makes all behind the scene magic.

##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. Open the LICENSE file that accompanies this distribution to see the full text of the license.

##Contribution

There are three ways you can help us:

  • Raise an issue. You found something that does not work as expected? Let us know about it.
  • Suggest a feature. It's even better if you come up with a new feature and write us about it.
  • Write some code. We would love to see more pull requests to our framework, just make sure you have the latest sources.

lib-obj-c-attr's People

Contributors

alexeyafanasyev avatar nikita-leonov avatar sinkevich avatar yuriy-tolstoguzov avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.