{"id":19113779,"url":"https://github.com/mugbug/awesome-swift","last_synced_at":"2026-02-06T05:30:58.938Z","repository":{"id":118463034,"uuid":"278083592","full_name":"mugbug/awesome-swift","owner":"mugbug","description":"🕶 A list of awesome helpers for Swift and iOS [WIP]","archived":false,"fork":false,"pushed_at":"2020-07-09T12:37:52.000Z","size":11,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-28T04:01:53.144Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mugbug.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-07-08T12:30:08.000Z","updated_at":"2020-08-05T21:14:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"40ae1f5f-ad5a-4f51-810d-7b9db3a603fc","html_url":"https://github.com/mugbug/awesome-swift","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mugbug/awesome-swift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mugbug%2Fawesome-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mugbug%2Fawesome-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mugbug%2Fawesome-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mugbug%2Fawesome-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mugbug","download_url":"https://codeload.github.com/mugbug/awesome-swift/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mugbug%2Fawesome-swift/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266117813,"owners_count":23879119,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T04:39:00.236Z","updated_at":"2026-02-06T05:30:58.905Z","avatar_url":"https://github.com/mugbug.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Awesome Swift\nA list of awesome helpers for Swift and iOS\n\n## Generic Builder DSL\n\nUsage:\n```swift\nextension UIView: Builder {}\n\nlazy var label = UILabel()\n    .. \\.text \u003c- \"Hello, World!\"\n    .. \\.font \u003c- .systemFont(ofSize: 40)\n    .. \\.textColor \u003c- .white\n```\n\nImplementation:\n```swift\ninfix operator ..: AdditionPrecedence\ninfix operator \u003c-: MultiplicationPrecedence\n\nstruct Predicate\u003cElement\u003e {\n    let code: (Element) -\u003e Element\n\n    func runCode(for element: Element) -\u003e Element {\n        return code(element)\n    }\n}\n\nfunc \u003c- \u003cElement, T\u003e(_ attribute: WritableKeyPath\u003cElement, T\u003e,\n                     _ constant: T) -\u003e Predicate\u003cElement\u003e {\n    return Predicate(code: { value in\n        var copy = value\n        copy[keyPath: attribute] = constant\n        return copy\n    })\n}\n\nprotocol Builder {}\n\nextension Builder {\n    @discardableResult\n    static func .. (_ element: Self,\n                    _ predicate: Predicate\u003cSelf\u003e) -\u003e Self {\n        return element.with(predicate)\n    }\n\n    private func with(_ predicate: Predicate\u003cSelf\u003e) -\u003e Self {\n        return predicate.runCode(for: self)\n    }\n}\n\n```\n---\n## Router/Coordinator pattern protocols\n\n- [x] PresentableRouter\n- [x] PushableRouter\n- [ ] TabBarRouter\n- [ ] TabPageRouter\n\n### PresentableRouter\n\nUsage:\n1. Make your Router implement `PresentableRouter`\n```swift\nfinal class SomeModalRouter: PresentableRouter {\n    // ...\n    \n}\n```\n2. Simply call its `start()` method\n```swift\nlet router = SomeModalRouter(...)\nrouter.start()\n```\n\nImplementation:\n```swift\nimport UIKit\n\nprotocol PresentableRouter: ShowableRouter {\n    var presentingViewController: UIViewController { get }\n}\n\nextension PresentableRouter {\n    func show(viewController: UIViewController, animated: Bool) {\n        currentViewController = viewController\n        presentingViewController.present(viewController, animated: animated)\n    }\n}\n```\n\nObs.: It requires `ShowableRouter` and `Router` protocols.\n\n---\n\n### PushableRouter\n\nUsage:\n1. Make your Router implement `PushableRouter`\n```swift\nfinal class SomeRouter: PushableRouter {\n    // ...\n    \n}\n```\n2. Simply call its `start()` method\n```swift\nlet router = SomeRouter(...)\nrouter.start()\n```\n\nImplementation:\n```swift\nimport UIKit\n\nprotocol PushableRouter: ShowableRouter {\n    var presentingViewController: UINavigationController { get }\n}\n\nextension PushableRouter {\n    func show(viewController: UIViewController, animated: Bool) {\n        currentViewController = viewController\n        presentingViewController.pushViewController(viewController, animated: animated)\n    }\n}\n```\n\nObs.: It requires `ShowableRouter` and `Router` protocols.\n\n--- \n\n### Router\n\nA prerequisite for `ShowableRouter`.\n\nImplementation:\n```swift\nimport UIKit\n\nprotocol Router: class {\n    var currentViewController: UIViewController? { get }\n    func start()\n    func start(animated: Bool)\n}\n\nextension Router {\n    func start() {\n        start(animated: true)\n    }\n}\n```\n\n### ShowableRouter\n\nA prerequisite for `PushableRouter`, `PresentableRouter`, `RootRouter` and `TabPageRouter`\n\nImplementation:\n```swift\nimport UIKit\n\nprotocol ShowableRouter: Router {\n    var currentViewController: UIViewController? { get set }\n    func createViewController() -\u003e UIViewController\n    func show(viewController: UIViewController, animated: Bool)\n}\n\nextension ShowableRouter {\n    func start(animated: Bool = true) {\n        let viewController = createViewController()\n        show(viewController: viewController, animated: animated)\n    }\n}\n```\n\n---\n\n## AppDelegateMock\n\nImplementation steps:\n1. Remove `@UIApplicationMain` from `AppDelegate.swift`\n2. Create a `main.swift` file and add this:\n\n```swift\n// main.swift\n\nimport UIKit\n\nlet appDelegateClass: AnyClass =\n    NSClassFromString(\"TestsAppDelegate\") ?? AppDelegate.self\n\nUIApplicationMain(\n    CommandLine.argc,\n    CommandLine.unsafeArgv,\n    nil,\n    NSStringFromClass(appDelegateClass)\n)\n```\n\n3. Create a `TestsAppDelegate.swift` file -- which will be our mock. \n4. Add it to the desired tests target\n5. Implement it:\n\n```swift\nimport UIKit\n@testable import YourProjectName\n\n@objc(TestsAppDelegate)\nclass TestsAppDelegate: UIResponder, UIApplicationDelegate {\n    var window: UIWindow?\n\n    func application(\n        _ application: UIApplication,\n        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?\n    ) -\u003e Bool {\n\n        // do some testing setup here\n\n        return true\n    }\n\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmugbug%2Fawesome-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmugbug%2Fawesome-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmugbug%2Fawesome-swift/lists"}