PluggableApplicationDelegate icon indicating copy to clipboard operation
PluggableApplicationDelegate copied to clipboard

Use Swift 4 lazy property override capability

Open basememara opened this issue 7 years ago • 2 comments

basememara avatar Jan 28 '18 04:01 basememara

Now you can do this:

open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
    
    public var window: UIWindow?
    
    private(set) lazy var services: [ApplicationService] = {
        return [ /* Populated from sub-class */ ]
    }()
}
@UIApplicationMain
class AppDelegate: PluggableApplicationDelegate {

    override lazy var services: [ApplicationService] = {
        return [
            LoggerApplicationService(),
            DataApplicationService(),
            AnalyticsApplicationService(),
            ThemeApplicationService()
        ]
    }()
}

basememara avatar Jan 28 '18 04:01 basememara

I think it's not necessary to apply here lazy loading. Since there is at least 1 service. Instead of an empty array, use fatalError() when the services not overwritten.

chosa91 avatar Apr 05 '18 15:04 chosa91