GithubHelp home page GithubHelp logo

lib-obj-c-attr's Introduction

Build Status License Platform

#libObjCAttr - attributes for your code

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

Our solution helps to reduce 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. Typical Podfile will looks like following:

pod 'libObjCAttr'

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

##Samples

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

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

Check out this example to get 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

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 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. Compatibility with 4.3 and older is not tested.

libObjCAttr was initially designed to use ARC.

##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.

lib-obj-c-attr's People

Contributors

nikita-leonov avatar sinkevich avatar

Watchers

 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.