-
-
Save krzysztofzablocki/6a1b6afab974f442f5ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController { | |
let coreDataStack: CoreDataStack | |
let mfpService = MFPService(username: x, password: y) | |
init(coreDataStack stack: CoreDataStack) { | |
coreDataStack = stack | |
let _ = integrator | |
let _ = rootFlowController | |
let _ = window | |
} | |
lazy var rootFlowController: FlowController = { | |
return SessionFlowController(coreDataStack: self.coreDataStack) | |
}() | |
lazy var window: UIWindow = { | |
let window = UIWindow(frame: UIScreen.mainScreen().bounds) | |
window.backgroundColor = UIColor.whiteColor() | |
window.rootViewController = self.rootFlowController.rootViewController | |
window.makeKeyAndVisible() | |
return window | |
}() | |
lazy var integrator: IntegrationService = { | |
let coreDataProcessor = CoreDataReportProcessor(stack: self.coreDataStack) | |
let integrator = IntegrationService(provider: self.mfpService) { | |
coreDataProcessor.processReports($0) | |
} | |
integrator.fetchEvery(interval: 5.hours) | |
integrator.fetch() | |
return integrator | |
}() | |
} |
How about Option 2 - lazy var’s with side-effects
+ builders
?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Private functions sounds like the most straight forward approach I would think. Who cares if it’s a static method or anything. Object oriented is only really about public interfaces. So just do something functional like Jessy’s https://gist.github.com/krzysztofzablocki/6a1b6afab974f442f5ff#gistcomment-1623209
Except I would call the functions
initIntegrator
orcreateIntegrator
instead of using pascal case, as they look like their own initialisers and types instead of simple functions.Nice work with this all by the way!