NSString+Additions.m 788 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #import "NSString+Additions.h"
  2. @implementation NSString (Additions)
  3. - (NSString *)nextVersionNumber {
  4. NSArray *comp = [self componentsSeparatedByString:@"-"];
  5. if (comp.count > 1){
  6. NSString *first = comp[0];
  7. NSInteger bumpVersion = [[comp lastObject] integerValue]+1;
  8. return [NSString stringWithFormat:@"%@-%lu", first, bumpVersion];
  9. } else {
  10. return nil;
  11. }
  12. return nil;
  13. }
  14. - (void)writeToFileWithoutAttributes:(NSString *)theFile {
  15. if ([FM fileExistsAtPath:theFile]){
  16. DLog(@"overwriting file: %@", theFile);
  17. }
  18. FILE *fd = fopen([theFile UTF8String], "w+");
  19. const char *text = self.UTF8String;
  20. fwrite(text, strlen(text) + 1, 1, fd);
  21. fclose(fd);
  22. }
  23. @end