Skip to content

Instantly share code, notes, and snippets.

@2bbb
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save 2bbb/b9256592401f21e2747a to your computer and use it in GitHub Desktop.

Select an option

Save 2bbb/b9256592401f21e2747a to your computer and use it in GitHub Desktop.
@interface NSString (AnotherClassExtension)
- (NSURL *)toURL;
- (NSURL *)toFileURL;
- (NSString *)toDocumentDirectoryPath;
- (NSURL *)toDocumentDirectoryFileURL;
- (NSString *)toCachePath;
- (NSURL *)toCacheFileURL;
- (UIImage* *)toImage;
@end
@implementation NSString (AnotherClassExtension)
- (NSURL *)toURL {
return [NSURL URLWithString:self];
}
- (NSURL *)toFileURL {
return [NSURL fileURLWithPath:self];
}
- (NSString *)toDocumentDirectoryPath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dir = paths[0];
return [dir stringByAppendingPathComponent:self];
}
- (NSURL *)toDocumentDirectoryFileURL {
return self.toDocumentDirectoryPath.toFileURL;
}
- (NSString *)toCachePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *dir = paths[0];
return [dir stringByAppendingPathComponent:self];
}
- (NSURL *)toCacheFileURL {
return self.toCachePath.toURL;
}
- (UIImage* *)toImage {
return [UIImage imageNamed:self];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment