AMRouter
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
-
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
-
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
-
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
-
Now create TWO pods:
-
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 onAMRouter
. -
Second one is
XxxComponent
, it should containXxxComponent.h
andXxxComponent.m
and any other necessary files which is in the component. And let this pod be dependent onXxxComponentInterface
.
-
-
🎉 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 andComponent
pod in your main project.You just need to import 1
AnotherComponentInterface
pod in yourOneComponent
pod.
Author
archmagees, [email protected]
License
AMRouter is available under the MIT license. See the LICENSE file for more info.