Last active
February 3, 2023 03:55
-
-
Save anatoliykant/757f5fa805b89bae9558b68392878802 to your computer and use it in GitHub Desktop.
objc DMVTestProgress (original)
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/Foundation.h> | |
typedef NS_ENUM(NSInteger, DMVTestProgressStatus) { | |
DMVTestProgressStatusEmpty, | |
DMVTestProgressStatusInProgress, | |
DMVTestProgressStatusPassed, | |
DMVTestProgressStatusFailed | |
}; | |
@interface DMVTestProgress : NSObject <NSSecureCoding> | |
- (instancetype)initWithTotalCount:(NSInteger)totalCount; | |
@property (assign, nonatomic) NSInteger totalCount; | |
@property (assign, nonatomic) NSInteger correctCount; | |
@property (assign, nonatomic) NSInteger wrongCount; | |
@property (assign, nonatomic) NSInteger skippedCount; | |
@property (assign, nonatomic) DMVTestProgressStatus status; | |
@property (assign, nonatomic) float percents; | |
@property (assign, nonatomic) BOOL adShown; | |
@property (assign, nonatomic, readonly) BOOL isPassed; | |
@property (assign, nonatomic, readonly) BOOL isCompleted; | |
- (long)getTotalAnswers; | |
- (long)getAnswersCount; | |
@end | |
@implementation DMVTestProgress | |
- (instancetype)initWithTotalCount:(NSInteger)totalCount { | |
self = [super init]; | |
if (self) { | |
self.totalCount = totalCount; | |
} | |
return self; | |
} | |
- (BOOL)isPassed { | |
return self.status == DMVTestProgressStatusPassed; | |
} | |
+ (BOOL)supportsSecureCoding { | |
return YES; | |
} | |
- (BOOL)isCompleted { | |
return self.status == DMVTestProgressStatusPassed || self.status == DMVTestProgressStatusFailed; | |
} | |
- (void)encodeWithCoder:(NSCoder *)aCoder { | |
[aCoder encodeInteger:self.totalCount forKey:NSStringFromSelector(@selector(totalCount))]; | |
[aCoder encodeInteger:self.correctCount forKey:NSStringFromSelector(@selector(correctCount))]; | |
[aCoder encodeInteger:self.wrongCount forKey:NSStringFromSelector(@selector(wrongCount))]; | |
[aCoder encodeInteger:self.skippedCount forKey:NSStringFromSelector(@selector(skippedCount))]; | |
[aCoder encodeInteger:self.status forKey:NSStringFromSelector(@selector(status))]; | |
[aCoder encodeFloat:self.percents forKey:NSStringFromSelector(@selector(percents))]; | |
[aCoder encodeBool:self.adShown forKey:NSStringFromSelector(@selector(adShown))]; | |
} | |
- (instancetype)initWithCoder:(NSCoder *)aDecoder { | |
self = [super init]; | |
if (self) { | |
self.totalCount = [aDecoder decodeIntegerForKey:NSStringFromSelector(@selector(totalCount))]; | |
self.correctCount = [aDecoder decodeIntegerForKey:NSStringFromSelector(@selector(correctCount))]; | |
self.wrongCount = [aDecoder decodeIntegerForKey:NSStringFromSelector(@selector(wrongCount))]; | |
self.skippedCount = [aDecoder decodeIntegerForKey:NSStringFromSelector(@selector(skippedCount))]; | |
self.status = [aDecoder decodeIntegerForKey:NSStringFromSelector(@selector(status))]; | |
self.percents = [aDecoder decodeFloatForKey:NSStringFromSelector(@selector(percents))]; | |
self.adShown = [aDecoder decodeBoolForKey:NSStringFromSelector(@selector(adShown))]; | |
} | |
return self; | |
} | |
- (long)getTotalAnswers { | |
return self.correctCount + self.wrongCount + self.skippedCount; | |
} | |
- (long)getAnswersCount { | |
return self.correctCount + self.wrongCount; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment