Swiftpack.co -  ZPP506/ZPPRouter as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
ZPP506/ZPPRouter
组件化路由 swift
.package(url: "https://github.com/ZPP506/ZPPRouter.git", from: "0.1.1")

ZPPRouter

  1. 面向组件协议
  2. 组件获取实例为协议类型

絕件C.png

: SPM 每一个组件最终生成的都是 framwork库 意味着组件存在命名空间(优点)

Example

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

Requirements

Installation

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

pod 'ZPPRouter'

Swift Package Manager

Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

Xcode 11+ is required to build ZPPRouter using Swift Package Manager.

To integrate ZPPRouter into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift:

dependencies: [
    .package(url: "https://github.com/ZPP506/ZPPRouter.git", .upToNextMajor(from: "0.1.1"))
]

ZPPRouter 使用示例:

  1. 定义 xxxProtocol
public protocol xxxProtocol: UIViewController {
    
}

  1. 实现获取方法
extension JLRouteProtocol where Self == ZPPRouter<xxxProtocol> {
    
    @discardableResult
    public static func makeDestination(config: ((xxxProtocol) -> Void)) -> xxxProtocol {
        let item = makeDestination()
        config(item)
        return item
    }
    
    @discardableResult
    public static func makeDestination() -> xxxProtocol {
        
        return UIViewController()
    }
}
extension UIViewController: xxxProtocol {}

  1. 获取 UIViewController
let vc = ZPPRouter<xxxProtocol>.makeDestination()

或者

ZPPRouter<xxxProtocol>.makeDestination {
   $0.view.backgroundColor = .red
}

Dome: https://github.com/ZPP506/ZPPRouter

推荐实践

ZPPRouterCenter:

  1. 引用所有组件

ZPPRouterService:

  1. 定义组件对外协议
  2. 定义获取组件方法

1.png 2.png 3.png 4.png 5.png 6.png 7.png

GitHub

link
Stars: 2
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics