The iOS framework that grows only as fast as its documentation
NIPaths.m
1 //
2 // Copyright 2011-2014 NimbusKit
3 //
4 // Forked from Three20 June 10, 2011 - Copyright 2009-2011 Facebook
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
18 
19 #import "NIPaths.h"
20 
21 #if !defined(__has_feature) || !__has_feature(objc_arc)
22 #error "Nimbus requires ARC support."
23 #endif
24 
25 NSString* NIPathForBundleResource(NSBundle* bundle, NSString* relativePath) {
26  NSString* resourcePath = [(nil == bundle ? [NSBundle mainBundle] : bundle) resourcePath];
27  return [resourcePath stringByAppendingPathComponent:relativePath];
28 }
29 
30 NSString* NIPathForDocumentsResource(NSString* relativePath) {
31  static NSString* documentsPath = nil;
32  if (nil == documentsPath) {
33  NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
34  NSUserDomainMask,
35  YES);
36  documentsPath = [dirs objectAtIndex:0];
37  }
38  return [documentsPath stringByAppendingPathComponent:relativePath];
39 }
40 
41 NSString* NIPathForLibraryResource(NSString* relativePath) {
42  static NSString* libraryPath = nil;
43  if (nil == libraryPath) {
44  NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
45  NSUserDomainMask,
46  YES);
47  libraryPath = [dirs objectAtIndex:0];
48  }
49  return [libraryPath stringByAppendingPathComponent:relativePath];
50 }
51 
52 NSString* NIPathForCachesResource(NSString* relativePath) {
53  static NSString* cachesPath = nil;
54  if (nil == cachesPath) {
55  NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
56  NSUserDomainMask,
57  YES);
58  cachesPath = [dirs objectAtIndex:0];
59  }
60  return [cachesPath stringByAppendingPathComponent:relativePath];
61 }
NSString * NIPathForBundleResource(NSBundle *bundle, NSString *relativePath)
Create a path with the given bundle and the relative path appended.
Definition: NIPaths.m:25
NSString * NIPathForLibraryResource(NSString *relativePath)
Create a path with the Library directory and the relative path appended.
Definition: NIPaths.m:41
NSString * NIPathForDocumentsResource(NSString *relativePath)
Create a path with the documents directory and the relative path appended.
Definition: NIPaths.m:30
NSString * NIPathForCachesResource(NSString *relativePath)
Create a path with the caches directory and the relative path appended.
Definition: NIPaths.m:52