/
DTVersion.h
158 lines (133 loc) · 5.18 KB
/
DTVersion.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//
// DTVersion.h
// DTFoundation
//
// Created by Oliver Drobnik on 11/25/11.
// Copyright (c) 2012 Cocoanetics. All rights reserved.
/**
Class that represents a version number comprised of major, minor and maintenance number separarated by dots. For example "1.2.2".
This encapsulation simplifies comparing versions against each other. Sub-numbers that are omitted on creating a `DTVersion` are assumed to be 0.
*/
@interface DTVersion : NSObject
{
NSUInteger _major;
NSUInteger _minor;
NSUInteger _maintenance;
NSUInteger _build;
}
/**-------------------------------------------------------------------------------------
@name Properties
---------------------------------------------------------------------------------------
*/
/**
The major version number
*/
@property (nonatomic, readonly) NSUInteger major;
/**
The minor version number
*/
@property (nonatomic, readonly) NSUInteger minor;
/**
The maintenance/hotfix version number
*/
@property (nonatomic, readonly) NSUInteger maintenance;
/**
The build number
*/
@property (nonatomic, readonly) NSUInteger build;
/**-------------------------------------------------------------------------------------
@name Creating Versions
---------------------------------------------------------------------------------------
*/
/**
Initializes the receiver with major, minor and maintenance version.
@param major The major version number
@param minor The minor version number
@param maintenance The maintainance/hotfix version number
@returns The initialized `DTVersion`
*/
- (DTVersion *)initWithMajor:(NSUInteger)major minor:(NSUInteger)minor maintenance:(NSUInteger)maintenance;
/**
Initializes the receiver with major, minor and maintenance version.
@param major The major version number
@param minor The minor version number
@param maintenance The maintainance/hotfix version number
@param build The build number
@returns The initialized `DTVersion`
*/
- (DTVersion *)initWithMajor:(NSUInteger)major minor:(NSUInteger)minor maintenance:(NSUInteger)maintenance build:(NSUInteger)build;
/**
creates and returns a DTVersion object initialized using the provided string
@param versionString The `NSString` to create a `DTVersion` from
@returns A DTVersion object or <code>nil</code> if the string is not a valid version number
*/
+ (DTVersion *)versionWithString:(NSString *)versionString;
/**
creates and retuns a DTVersion object initialized with the version information of the current application
@returns A DTVersion object or <code>nil</code> if the string of the current application is not a valid version number
*/
+ (DTVersion *)appBundleVersion;
/**
creates and retuns a DTVersion object initialized with the version information of the operating system
@returns A DTVersion object or <code>nil</code> if the string of the current application is not a valid version number
*/
+ (DTVersion *)osVersion;
/**-------------------------------------------------------------------------------------
@name Comparing Versions
---------------------------------------------------------------------------------------
*/
/**
@param versionString The OS version as `NSString` to compare the receiver to
@returns <code>true</code> if the given version string is valid and less then the osVersion
*/
+ (BOOL)osVersionIsLessThen:(NSString *)versionString;
/**
@param versionString The OS version as `NSString` to compare the receiver to
@returns <code>true</code> if the given version string is valid and greater then the osVersion
*/
+ (BOOL)osVersionIsGreaterThen:(NSString *)versionString;
/**
@param version The `DTVersion` to compare the receiver to
@returns <code>true</code> if the give version is less then this version
*/
- (BOOL)isLessThenVersion:(DTVersion *)version;
/**
@param version The `DTVersion` to compare the receiver to
@returns <code>true</code> if the give version is greater then this version
*/
- (BOOL)isGreaterThenVersion:(DTVersion *)version;
/**
@param versionString The version as `NSString` to compare the receiver to
@returns <code>true</code> if the give version is less then this version string
*/
- (BOOL)isLessThenVersionString:(NSString *)versionString;
/**
@param versionString The version as `NSString` to compare the receiver to
* @returns <code>true</code> if the give version is greater then version string
*/
- (BOOL)isGreaterThenVersionString:(NSString *)versionString;
/**
Compares the receiver against a passed `DTVersion` instance
@param version The `DTVersion` to compare the receiver to
@returns `YES` is the versions are equal
*/
- (BOOL)isEqualToVersion:(DTVersion *)version;
/**
Compares the receiver against a passed version as `NSString`
@param versionString The version as `NSString` to compare the receiver to
@returns `YES` is the versions are equal
*/
- (BOOL)isEqualToString:(NSString *)versionString;
/**
Compares the receiver against a passed object
@param object An object of either `NSString` or `DTVersion`
@returns `YES` is the versions are equal
*/
- (BOOL)isEqual:(id)object;
/**
Compares the receiver against a passed `DTVersion` instance
@param version The `DTVersion` to compare the receiver to
@returns The comparison result
*/
- (NSComparisonResult)compare:(DTVersion *)version;
@end