Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
GMRouter
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
GMRouter
Commits
8160d8d4
Commit
8160d8d4
authored
Dec 13, 2019
by
jz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化GMRouter
parent
db494233
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
13 deletions
+22
-13
GMRouter+gm.h
GMRouter/Classes/GMRouter+gm.h
+7
-0
GMRouter+gm.m
GMRouter/Classes/GMRouter+gm.m
+13
-13
GMRouter.m
GMRouter/Classes/GMRouter.m
+2
-0
No files found.
GMRouter/Classes/GMRouter+gm.h
View file @
8160d8d4
...
@@ -98,6 +98,13 @@ void removeSelectorToMediator(NSString *clsName);
...
@@ -98,6 +98,13 @@ void removeSelectorToMediator(NSString *clsName);
*
*
*/
*/
-
(
id
)
pushScheme
:(
NSString
*
)
urlScheme
params
:(
NSDictionary
*
)
params
;
-
(
id
)
pushScheme
:(
NSString
*
)
urlScheme
params
:(
NSDictionary
*
)
params
;
/**
* 初始化Map
*
*/
-
(
void
)
initializeRouteMap
;
@end
@end
NS_ASSUME_NONNULL_END
NS_ASSUME_NONNULL_END
GMRouter/Classes/GMRouter+gm.m
View file @
8160d8d4
...
@@ -33,28 +33,25 @@ NSString *const GMRouterTargetWeb = @"Target_Web";
...
@@ -33,28 +33,25 @@ NSString *const GMRouterTargetWeb = @"Target_Web";
static
NSMutableDictionary
*
routeMap
=
nil
;
static
NSMutableDictionary
*
routeMap
=
nil
;
@implementation
GMRouter
(
gm
)
@implementation
GMRouter
(
gm
)
+
(
void
)
initialize
{
if
(
!
routeMap
)
{
-
(
void
)
initializeRouteMap
{
routeMap
=
[[
NSMutableDictionary
alloc
]
initWithCapacity
:
50
];
routeMap
=
[[
NSMutableDictionary
alloc
]
initWithCapacity
:
50
];
NSArray
*
arr
=
@[
GMRouterTargetAI
,
GMRouterTargetBanking
,
GMRouterTargetCommunity
,
GMRouterTargetWeb
];
NSArray
*
arr
=
@[
GMRouterTargetAI
,
GMRouterTargetBanking
,
GMRouterTargetCommunity
,
GMRouterTargetWeb
];
for
(
NSString
*
clsStr
in
arr
)
{
for
(
NSString
*
clsStr
in
arr
)
{
NSDictionary
*
dict
=
[
self
getMethods
:
clsStr
];
NSDictionary
*
dict
=
[
self
getMethods
:
clsStr
];
[
routeMap
addEntriesFromDictionary
:
dict
];
[
routeMap
addEntriesFromDictionary
:
dict
];
}
}
}
}
}
#pragma mark - 获取类的所有方法
#pragma mark - 获取类的所有方法
// 获取所有的方法
// 获取所有的方法
+
(
NSDictionary
*
)
getMethods
:
(
NSString
*
)
clsStr
{
-
(
NSDictionary
*
)
getMethods
:
(
NSString
*
)
clsStr
{
Class
cls
=
NSClassFromString
(
clsStr
);
Class
cls
=
NSClassFromString
(
clsStr
);
NSRange
range
=
[
clsStr
rangeOfString
:
@"Target_"
];
NSRange
range
=
[
clsStr
rangeOfString
:
@"Target_"
];
NSString
*
targetValue
=
[
clsStr
substringFromIndex
:
range
.
length
];
NSString
*
targetValue
=
[
clsStr
substringFromIndex
:
range
.
length
];
if
(
!
targetValue
.
length
)
{
return
@{};
}
NSObject
*
target
=
[[
cls
alloc
]
init
];
NSAssert
(
targetValue
.
length
!=
0
,
@"Target_后不能为空!请注意Target"
);
unsigned
int
count
=
0
;
unsigned
int
count
=
0
;
NSMutableDictionary
*
dict
=
[
NSMutableDictionary
dictionary
];
NSMutableDictionary
*
dict
=
[
NSMutableDictionary
dictionary
];
...
@@ -75,6 +72,9 @@ static NSMutableDictionary *routeMap = nil;
...
@@ -75,6 +72,9 @@ static NSMutableDictionary *routeMap = nil;
}
}
// 获取方法的参数列表
// 获取方法的参数列表
int
arguments
=
method_getNumberOfArguments
(
methods
[
i
]);
int
arguments
=
method_getNumberOfArguments
(
methods
[
i
]);
NSAssert
([
dict
.
allKeys
containsObject
:
name
],
@"Target_后不能为空!请注意Target"
);
//因为消息发送的时候会有两个默认的参数(消息接受者和方法名),所以需要减去2
//因为消息发送的时候会有两个默认的参数(消息接受者和方法名),所以需要减去2
dict
[
name
]
=
targetValue
;
dict
[
name
]
=
targetValue
;
}
}
...
...
GMRouter/Classes/GMRouter.m
View file @
8160d8d4
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
//
//
#import "GMRouter.h"
#import "GMRouter.h"
#import "GMRouter+gm.h"
NSString
*
const
GMRouterParamsKeySwiftTargetModuleName
=
@"GMRouterParamsKeySwiftTargetModuleName"
;
NSString
*
const
GMRouterParamsKeySwiftTargetModuleName
=
@"GMRouterParamsKeySwiftTargetModuleName"
;
...
@@ -22,6 +23,7 @@ NSString * const GMRouterParamsKeySwiftTargetModuleName = @"GMRouterParamsKeySwi
...
@@ -22,6 +23,7 @@ NSString * const GMRouterParamsKeySwiftTargetModuleName = @"GMRouterParamsKeySwi
static
dispatch_once_t
onceToken
;
static
dispatch_once_t
onceToken
;
dispatch_once
(
&
onceToken
,
^
{
dispatch_once
(
&
onceToken
,
^
{
router
=
[[
GMRouter
alloc
]
init
];
router
=
[[
GMRouter
alloc
]
init
];
[
router
initializeRouteMap
];
});
});
return
router
;
return
router
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment