Skip to content

Instantly share code, notes, and snippets.

@Eeyore741
Last active July 9, 2018 13:52
Show Gist options
  • Select an option

  • Save Eeyore741/3e69be5e8e2372882a1ee5a1433d728f to your computer and use it in GitHub Desktop.

Select an option

Save Eeyore741/3e69be5e8e2372882a1ee5a1433d728f to your computer and use it in GitHub Desktop.
Pineapples count functions
- (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