-
Notifications
You must be signed in to change notification settings - Fork 1
/
NSBundle+Convenience.m
63 lines (48 loc) · 1.84 KB
/
NSBundle+Convenience.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// NSBundle+Convenience.m
// Sleep Diary
//
// Created by Alexander Ivanov on 15.03.16.
// Copyright © 2016 Alexander Ivanov. All rights reserved.
//
#import "NSBundle+Convenience.h"
@implementation NSBundle (Convenience)
- (NSURL *)URLForResource:(NSString *)name {
return [self URLForResource:name.lastPathComponent.stringByDeletingPathExtension withExtension:name.pathExtension subdirectory:name.stringByDeletingLastPathComponent];
}
+ (NSURL *)URLForResource:(NSString *)name {
return [[self mainBundle] URLForResource:name];
}
- (NSString *)pathForResource:(NSString *)name {
return [self pathForResource:name.stringByDeletingPathExtension ofType:name.pathExtension];
}
+ (NSString *)pathForResource:(NSString *)name {
return [[self mainBundle] pathForResource:name];
}
+ (NSString *)mainLocalization {
return [self mainBundle].preferredLocalizations.firstObject;
}
- (BOOL)isPreferredLocalization:(NSString *)localization {
return [self.preferredLocalizations any:^BOOL(NSString *item) {
return [localization isEqualToString:item];
}];
}
+ (BOOL)isPreferredLocalization:(NSString *)localization {
return [[self mainBundle] isPreferredLocalization:localization];
}
+ (NSString *)bundleIdentifier {
return [self mainBundle].bundleIdentifier;
}
+ (NSString *)bundleDisplayName {
return [[self mainBundle] objectForInfoDictionaryKey:CFBundleDisplayName] ?: [[self mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleNameKey];
}
+ (NSString *)bundleShortVersionString {
return [[self mainBundle] objectForInfoDictionaryKey:CFBundleShortVersionString];
}
+ (NSString *)bundleVersion {
return [[self mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
}
+ (NSString *)bundleDisplayNameAndShortVersion {
return [NSString stringWithFormat:@"%@ %@", [self bundleDisplayName], [self bundleShortVersionString]];
}
@end