Last active
July 9, 2018 13:52
-
-
Save Eeyore741/3e69be5e8e2372882a1ee5a1433d728f to your computer and use it in GitHub Desktop.
Pineapples count functions
This file contains hidden or 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
| - (NSString *)pineappleStringWithCount:(int)count{ | |
| if (count == 0) { | |
| return @"У Джона нет ананасов"; | |
| } | |
| NSString *countString = [[NSString alloc] initWithFormat:@"%u", self.pineappleCount]; | |
| if (self.pineappleCount >= 10) { | |
| int secondLastDigit = [[countString substringWithRange:NSMakeRange(countString.length-2, 1)] intValue]; | |
| if (secondLastDigit == 1) { | |
| return [NSString stringWithFormat:@"У Джона %u ананасов", count]; | |
| } | |
| } | |
| int oneLastDigit = [[countString substringFromIndex:countString.length-1] intValue]; | |
| if (oneLastDigit == 0 || (oneLastDigit > 4 && oneLastDigit <= 9)) { | |
| return [NSString stringWithFormat:@"У Джона %u ананасов", count]; | |
| } | |
| else | |
| if (oneLastDigit == 1) { | |
| return [NSString stringWithFormat:@"У Джона %u ананас", count]; | |
| } | |
| else | |
| if (oneLastDigit >= 2 && oneLastDigit <= 4) { | |
| return [NSString stringWithFormat:@"У Джона %u ананаса", count]; | |
| } | |
| return nil; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment