Skip to content

Instantly share code, notes, and snippets.

@anatoliykant
Created February 3, 2023 03:53
Show Gist options
  • Save anatoliykant/c69fed7bbfb47f6f244d2879034ccacb to your computer and use it in GitHub Desktop.
Save anatoliykant/c69fed7bbfb47f6f244d2879034ccacb to your computer and use it in GitHub Desktop.
swift DMVTestProgress (swiftify.com)
enum DMVTestProgressStatus : Int {
case empty
case inProgress
case passed
case failed
}
//totalCount
//self
//DMVTestProgressStatusPassed
//DMVTestProgressStatusFailed
class DMVTestProgress: NSObject, NSSecureCoding {
var totalCount = 0
var correctCount = 0
var wrongCount = 0
var skippedCount = 0
var status: DMVTestProgressStatus!
var percents: Float = 0.0
var adShown = false
init(totalCount: Int) {
super.init()
self.totalCount = totalCount
}
func isPassed() -> Bool {
return status == DMVTestProgressStatusPassed
}
class var supportsSecureCoding: Bool {
return true
}
var isCompleted: Bool {
get {
return status == DMVTestProgressStatusPassed || status == DMVTestProgressStatusFailed
}
set {
super.isCompleted = newValue
}
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
func encode(with aCoder: NSCoder) {
aCoder.encode(totalCount, forKey: NSStringFromSelector(#selector(MXSignpostMetric.totalCount)))
aCoder.encode(correctCount, forKey: NSStringFromSelector(Selector("correctCount")))
aCoder.encode(wrongCount, forKey: NSStringFromSelector(Selector("wrongCount")))
aCoder.encode(skippedCount, forKey: NSStringFromSelector(Selector("skippedCount")))
aCoder.encode(status, forKey: NSStringFromSelector(Selector("status")))
aCoder.encode(percents, forKey: NSStringFromSelector(Selector("percents")))
aCoder.encode(adShown, forKey: NSStringFromSelector(Selector("adShown")))
}
required init?(coder aDecoder: NSCoder) {
super.init()
totalCount = aDecoder.decodeInteger(forKey: NSStringFromSelector(#selector(MXSignpostMetric.totalCount)))
correctCount = aDecoder.decodeInteger(forKey: NSStringFromSelector(Selector("correctCount")))
wrongCount = aDecoder.decodeInteger(forKey: NSStringFromSelector(Selector("wrongCount")))
skippedCount = aDecoder.decodeInteger(forKey: NSStringFromSelector(Selector("skippedCount")))
status = aDecoder.decodeInteger(forKey: NSStringFromSelector(Selector("status")))
percents = aDecoder.decodeFloat(forKey: NSStringFromSelector(Selector("percents")))
adShown = aDecoder.decodeBool(forKey: NSStringFromSelector(Selector("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