Last active
February 3, 2023 03:55
-
-
Save anatoliykant/764a71d74fb559b70401bc94d9c7476f to your computer and use it in GitHub Desktop.
swift DMVTestProgress (ChatGPT - chat.openai.com)
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
import Foundation | |
enum DMVTestProgressStatus: Int { | |
case empty | |
case inProgress | |
case passed | |
case failed | |
} | |
class DMVTestProgress: NSObject, NSSecureCoding { | |
init(totalCount: Int) { | |
self.totalCount = totalCount | |
} | |
var totalCount: Int | |
var correctCount: Int = 0 | |
var wrongCount: Int = 0 | |
var skippedCount: Int = 0 | |
var status: DMVTestProgressStatus = .empty | |
var percents: Float = 0 | |
var adShown: Bool = false | |
var isPassed: Bool { | |
return status == .passed | |
} | |
static var supportsSecureCoding: Bool { | |
return true | |
} | |
var isCompleted: Bool { | |
return status == .passed || status == .failed | |
} | |
func encode(with coder: NSCoder) { | |
coder.encode(totalCount, forKey: NSStringFromSelector(#selector(getter: totalCount))) | |
coder.encode(correctCount, forKey: NSStringFromSelector(#selector(getter: correctCount))) | |
coder.encode(wrongCount, forKey: NSStringFromSelector(#selector(getter: wrongCount))) | |
coder.encode(skippedCount, forKey: NSStringFromSelector(#selector(getter: skippedCount))) | |
coder.encode(status.rawValue, forKey: NSStringFromSelector(#selector(getter: status))) | |
coder.encode(percents, forKey: NSStringFromSelector(#selector(getter: percents))) | |
coder.encode(adShown, forKey: NSStringFromSelector(#selector(getter: adShown))) | |
} | |
required init?(coder: NSCoder) { | |
totalCount = coder.decodeInteger(forKey: NSStringFromSelector(#selector(getter: totalCount))) | |
correctCount = coder.decodeInteger(forKey: NSStringFromSelector(#selector(getter: correctCount))) | |
wrongCount = coder.decodeInteger(forKey: NSStringFromSelector(#selector(getter: wrongCount))) | |
skippedCount = coder.decodeInteger(forKey: NSStringFromSelector(#selector(getter: skippedCount))) | |
status = DMVTestProgressStatus(rawValue: coder.decodeInteger(forKey: NSStringFromSelector(#selector(getter: status)))) ?? .empty | |
percents = coder.decodeFloat(forKey: NSStringFromSelector(#selector(getter: percents))) | |
adShown = coder.decodeBool(forKey: NSStringFromSelector(#selector(getter: adShown))) | |
} | |
func getTotalAnswers() -> Int { | |
return correctCount + wrongCount + skippedCount | |
} | |
func getAnswersCount() -> Int { | |
return correctCount + wrongCount | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment