Skip to content

Instantly share code, notes, and snippets.

@krzysztofzablocki
Created November 17, 2015 14:14
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save krzysztofzablocki/6a1b6afab974f442f5ff to your computer and use it in GitHub Desktop.
Save krzysztofzablocki/6a1b6afab974f442f5ff to your computer and use it in GitHub Desktop.
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
}()
}
@RoyalIcing
Copy link

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 or createIntegrator 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!

@onmyway133
Copy link

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