Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protocol Calculable {
- // The calc logic you were going to have in SessionHelper
- func calc()
- }
- protocol Timeable {
- // The same timeElapsed property you had before
- var timeElapsed: TimeInterval { get }
- }
- class Session {
- var start: Date
- var end: Date
- init() {
- self.start = Date()
- self.end = Date()
- }
- }
- // Mark: - Timeable Conformance -
- extension Session: Timeable {
- var timeElapsed: TimeInterval {
- return calcSomething(start, end, pauses, resumes)
- }
- }
- // MARK: - Calculable Conformance
- extension Session: Calculable {
- func calc() {
- // Perform the logic for calculating right in here using timeElapsed computed property
- }
- }
Add Comment
Please, Sign In to add comment