ãã¼ã¸ã§ã³çªå·ã®æååãæ¯è¼ããæ¹æ³
Objective-Cã§ã¯ãã¼ã¸ã§ã³ã®æååã®æ¯è¼ã¯ NSString ã® compare:options: ã¡ã½ããã« NSNumericSearch ãæå®ãã¦è¡ãã¾ãã
NSString *versionA = @"1.0.0"; NSString *versionB = @"1.41.0"; if ([versionA compare:versionB options:NSNumericSearch] == NSOrderedAscending) { // æé (NSOrderedAscendingãversionA < versionB)ã®ã¨ã NSLog(@"æé "); } else { NSLog(@"æé ã§ç¡ã"); }
ãã¾ãã¾ãªãã¿ã¼ã³ã®å¤ãæå®ããã¨ãã®çµæã以ä¸ã«ã¾ã¨ãã¾ããã
[versionA compare:versionB options:NSNumericSearch];
ã¨è¨è¿°ããã¨ãã® versionA 㨠versionB ã®å¤ã®ä¸¦ã³é ã NSOrderedSame,NSOrderedAscending,NSOrderedDescending ã®ããããã§è¿ãã¾ãã
ã¡ãã£ã¨æ¥æ¬äººã«ã¯ç´æçã§ã¯ãªãã®ã§NSOrderedSame=çãããNSOrderedAscending=æé ãNSOrderedDescending=éé ã¨ãã¦è¨è¿°ãã¾ããã
versionA | versionB | æ¯è¼çµæ |
---|---|---|
1.0.0 | 1.41.0 | æé |
2.0.0 | 1.41.0 | éé |
1.0 | 1.41.0 | æé |
2.0 | 1.41.0 | éé |
1 | 1.41.0 | æé |
2 | 1.41.0 | éé |
1.5.0 | 1.41.0 | æé |
1.50.0 | 1.41.0 | éé |
1.4.0 | 1.41.0 | æé |
1.41.0 | 1.41.0 | çãã |
1.40.99 | 1.41.0 | æé |
1.4.99 | 1.41.0 | æé |
0.99.99 | 1.41.0 | æé |
ãã®æ§ã«ã©ã®æ§ãªãã¿ã¼ã³ã§è¨è¿°ããããã¼ã¸ã§ã³çªå·ã®ã¨ãã§ãçæ³çãªçµæãè¿ããã¾ãã