AMRouter 0.3.0

AMRouter 0.3.0

Maintained by Arthur.



AMRouter 0.3.0

  • By
  • Arthur

AMRouter

Build Status Coverage Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

iOS 9.0

Installation

AMRouter is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'AMRouter'

Usage

  1. Create a class, and it's name format should be like this: ShareComponent , MessageComponent.

    If your module function is share, then you should create a file with name ShareComponent.

    For example:

    #import <Foundation/Foundation.h>
    @interface MessageComponent : NSObject
    @end
  2. Create a protocol file, and define the methods that you want the class(i.e. just created) exploded, for example:

    @protocol MessageComponentInterface <NSObject>
    @required
    - (BOOL)notificationEnabled;
    @end

    Now let the class you created in step 1 conform the protocol you just created, then it should be like this now:

    #import <Foundation/Foundation.h>
    #import "MessageComponentInterface.h"
    @interface MessageComponent : NSObject <MessageComponentInterface>
    @end
  3. Now, here comes to step 3, the very important one. Create a category file which class is AMComponent . And create a public class method, like this:

    #import <AMRouter/AMRouter.h>
    #import "MessageComponentInterface.h"
    @interface AMComponent (Message)
    + (id<MessageComponentInterface>)message;
    @end
        
    #import "AMComponent+Message.h"
    static NSString * const kTargetName = @"Message";
    @implementation AMComponent (Message)
    + (id<MessageComponentInterface>)message {
        return [self targetWithName:kTargetName
                        classPrefix:nil
                componentNameSuffix:nil
                        shouldCache:YES];
    }
    @end
  4. Now create TWO pods:

    1. One pod, it's name is XxxComponentInterface, it should contain these 3 files:

      XxxComponentInterface.h(it is also a protocol file), AMComponent+Xxx.h andAMComponent+Xxx.m . And let this pods be dependent on AMRouter .

    2. Second one is XxxComponent , it should contain XxxComponent.h and XxxComponent.m and any other necessary files which is in the component. And let this pod be dependent on XxxComponentInterface .

  5. 🎉Finished! Now you can import the function in another module now, import way is like this:

    BOOL enabled = [[AMComponent message] notificationEnabled];

    It is only need to be dependent on 1 pod in Podfile , that is:

    pod 'XxxComponentInterface'

    You only need to import both Interface pod and Component pod in your main project.

    You just need to import 1 AnotherComponentInterface pod in your OneComponent pod.

Author

archmagees, [email protected]

License

AMRouter is available under the MIT license. See the LICENSE file for more info.