1st approach:
let whatsNewHandler = WhatsNewHandler(buildNumber: buildNumber)
whatsNewHandler.showWhatNewScreeen(completion: { whatsNewVC in
self.present(whatsNewVC, animated: true, completion: nil)
})
2nd approach, which looks a bit functional:
WhatsNewHandler(buildNumber: buildNumber).showWhatNewScreeen(completion: { whatsNewVC in
self.present(whatsNewVC, animated: true, completion: nil)
})
While both allocate the same amount of memory. I like the functional approach, I just do something and that's really it. But the reason I'm asking is I haven't seen anyone write like this. I see things similar to it when you're using a singleton, but this isn't a singleton.
EDIT:
My WhatNewHandler class:
import Foundation
import UIKit
typealias WhatsNewCompletionHandler = (_ whatsNewViewController: WhatsNewViewController) -> ()
class WhatsNewHandler{
let buildNumber : String
lazy var route : Router = {
return Router.whatsNew(buildNumber: self.buildNumber)
}()
init(buildNumber: String){
self.buildNumber = buildNumber
}
func showWhatNewScreeen(completion: @escaping WhatsNewCompletionHandler){
NetworkHandler.sharedInstance.request(route, success: { json,_ in
guard let json = json else{
writelog("what's new json was nil")
return
}
if let releaseBuild = ReleaseBuild(json: json){
let WhatsNewVC = WhatsNewViewController(releaseBuild: releaseBuild)
WhatsNewVC.modalPresentationStyle = .overFullScreen
// TEST ALPHA ON REAL DEVICE
WhatsNewVC.view.backgroundColor = UIColor.black.withAlphaComponent(0.985)
completion(WhatsNewVC)
}
}, failed: {_,_,_ in
})
}
}
As for my WhatsNewViewController, kindly assume it to be a Viewcontroller that shows a list of new features added to the app.