Skip to content
/ Modular Public

A modular swift project,Swift组件化方案,组件化,swift组件化,swift模块化,iOS组件化,模块化,组件化,组件开发,模块,模块开发

Notifications You must be signed in to change notification settings

gu0315/Modular

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Modular

iOS组件化

通过协议,利用perform实现的iOS组件化方案,逻辑清晰,支持参数校验,使用简单方便, 可以下载Demo查看使用

图片替换文本

安装

pod 'SModular'

使用

Swift

 static func moduleDescription(description: ModuleDescription) {
        description.moduleName("testSwift")
            .method { method in
                method.classMethod(true)
                      .name("push")
                      .selector(selector: #selector(push(str:callback:)))
                      .parameterDescription { enumerator in
                          enumerator.next()?.add(paramName: "str", paramType: .String)
                          enumerator.next()?.add(paramName: "callback", paramType: .Block)
                      }
            }
            .method { method in
                method.name("present")
                      .selector(selector: #selector(present(str:callback:)))
                      .parameterDescription { enumerator in
                          enumerator.next()?.add(paramName: "str", paramType: .String)
                          enumerator.next()?.add(paramName: "callback", paramType: .Block)
                      }
            }
            .method { method in
                method.name("log")
                      .selector(selector: #selector(printLog(logString:callback:)))
                      .parameterDescription { enumerator in
                          enumerator.next()?.add(paramName: "logString", paramType: .String)
                          enumerator.next()?.add(paramName: "callback", paramType: .Block)
                      }
            }
            .method { method in
                method.name("testNorm")
                      .selector(selector: #selector(testNorm(value:callback:)))
                      .parameterDescription { enumerator in
                          enumerator.next()?.add(paramName: "value", paramType: .String)
                          enumerator.next()?.add(paramName: "callback", paramType: .Block)
                      }
            }
            .method { method in
                method.name("multiparameter")
                      .selector(selector: #selector(multiparams(params1: params2: params3: params4: callback:)))
                      .parameterDescription { enumerator in
                          enumerator.next()?.add(paramName: "params1", paramType: .String)
                          enumerator.next()?.add(paramName: "params2", paramType: .Array)
                          enumerator.next()?.add(paramName: "params3", paramType: .Map)
                          enumerator.next()?.add(paramName: "params4", paramType: .Number)
                          enumerator.next()?.add(paramName: "callback", paramType: .Block)
                      }
            }
    }

OC

+ (void)moduleDescriptionWithDescription:(ModuleDescription * _Nonnull)description {
    description.moduleNameClosure(@"testOC")
        .methodClosure(^(ModuleMethod * moduleMethod) {
            [moduleMethod selectorWithSelector: @selector(push:callback:)];
            [moduleMethod name:@"push"];
            [moduleMethod parameterDescription:^(ModuleParameterDes * enumerator) {
                [[enumerator next] addWithParamName:@"dic" paramType:  ModuleParameterTypeMap  isStrict:NO];
                [[enumerator next] addWithParamName:@"callback" paramType: ModuleParameterTypeBlock isStrict:NO];
            }];
        })
        .methodClosure(^(ModuleMethod * moduleMethod) {
            [moduleMethod selectorWithSelector: @selector(present:)];
            [moduleMethod name:@"present"];
            [moduleMethod classMethod:YES];
            [moduleMethod parameterDescription:^(ModuleParameterDes * enumerator) {
                [[enumerator next] addWithParamName:@"dic" paramType:  ModuleParameterTypeMap  isStrict:NO];
            }];
        })
        .methodClosure(^(ModuleMethod * moduleMethod) {
            [moduleMethod selectorWithSelector: @selector(multiparameterLog:callback:)];
            [moduleMethod name:@"log"];
            [moduleMethod parameterDescription:^(ModuleParameterDes * enumerator) {
                [[enumerator next] addWithParamName:@"dic" paramType:  ModuleParameterTypeMap  isStrict:NO];
                [[enumerator next] addWithParamName:@"callback" paramType: ModuleParameterTypeBlock isStrict:NO];
            }];
        });
}

调用

Module.share.performWithUrl(url:"scheme:https://push/testSwift?str=1111"){ parameters in
                //页面参数回调
                print("调用模块方法的回调-》", parameters)
            }
Module.share.perform(moduleName: "testOC", selectorName: "present", params: [
                "dic": ["key": "value"]
            ]) { parameters in
                //页面参数回调
                print("调用模块方法的回调-》", parameters)
            }
Module.share.perform(moduleName:"testSwift", selectorName: "present", params: [
                "str": "present"
            ]) { parameters in
                //页面参数回调
                print("调用模块方法的回调-》", parameters)
            }

TODO

支持多参数 404界面 等等

About

A modular swift project,Swift组件化方案,组件化,swift组件化,swift模块化,iOS组件化,模块化,组件化,组件开发,模块,模块开发

Resources

Stars

Watchers

Forks

Packages

No packages published