Questions tagged [nsbundle]

An NSBundle object represents a location in the file system that groups code and resources that can be used in a program. NSBundle objects locate program resources, dynamically load and unload executable code, and assist in localization. You build a bundle in Xcode using one of these project types: Application, Framework, plug-ins.

An NSBundle object represents a location in the file system that groups code and resources that can be used in a program. NSBundle objects locate program resources, dynamically load and unload executable code, and assist in localization. You build a bundle in Xcode using one of these project types: Application, Framework, plug-ins.

568 questions
208
votes
8 answers

Why can't code inside unit tests find bundle resources?

Some code I am unit testing needs to load a resource file. It contains the following line: NSString *path = [[NSBundle mainBundle] pathForResource:@"foo" ofType:@"txt"]; In the app it runs just fine, but when run by the unit testing framework…
benzado
  • 82,288
  • 22
  • 110
  • 138
113
votes
16 answers

Getting version and build information with Swift

I am attempting to gain access to the main NSBundle to retrieve version and build information. Thing is, I want to try it in Swift, I know how to retrieve it in Objective-C with: text = [NSBundle.mainBundle.infoDictionary…
Ken-UbiDex
  • 1,213
  • 2
  • 8
  • 7
83
votes
8 answers

NSURL to file path in test bundle with XCTest

I am trying to write an iOS app using TDD and the new XCTest framework. One of my methods retrieves a file from the internet (given a NSURL object) and stores it in the user's documents. The signature of the method is similar to: - (void)…
Eduardo Arenas Prada
  • 1,072
  • 1
  • 7
  • 14
79
votes
4 answers

Write a file on iOS

How do I write a file on iOS? I'm trying to do it with the following code but I'm doing something wrong: char *saves = "abcd"; NSData *data = [[NSData alloc] initWithBytes:saves length:4]; NSArray *paths =…
Riccardo Queri
  • 1,025
  • 1
  • 10
  • 16
72
votes
8 answers

Load files in xcode unit tests

I have an Xcode 5 unit test project and some test xml files related to it. I've tried a bunch of approaches but I can't seem to load the xml files. I've tried the following which does not work NSData* nsData = [NSData…
ArdenDev
  • 4,051
  • 5
  • 29
  • 50
70
votes
6 answers

Access Asset Catalog pathForResource

It appears that: [[NSBundle mainBundle] pathForResource:@"name" ofType:@"png"]; Does not return anything for assets that are inside the Images.xcassets asset catalog. I also tried: [[NSBundle mainBundle] pathForResource:@"name" ofType:@"png"…
MobileVet
  • 2,958
  • 2
  • 26
  • 42
68
votes
7 answers

How to get bundle ID?

I am working on getting the facebook API working for iOS, and the FB registration page requires the Bundle ID of the project. How can I get this information? I read something about getting it at run time, but is there a way to get Xcode to tell me…
vjuliano
  • 1,474
  • 2
  • 15
  • 29
58
votes
3 answers

Get file path and URL for file in temp directory

I'm trying to get the file path of a file called "temp.pdf" which is located in the NSTemporaryDirectory folder (I've checked, the file exists). I use this: NSString *filePath = [[NSBundle mainBundle] pathForResource:@"temp" ofType:@"pdf"…
HasgardLucian
  • 613
  • 1
  • 5
  • 6
52
votes
5 answers

How can you determine if a file exists within the app bundle?

Sorry, dumb question number 2 today. Is it possible to determine if a file is contained within the App Bundle? I can access files no problem, i.e., NSString *pathAndFileName = [[NSBundle mainBundle] pathForResource:fileName ofType:@"plist"]; But…
Magic Bullet Dave
  • 9,006
  • 10
  • 51
  • 81
43
votes
10 answers

accessing a file using [NSBundle mainBundle] pathForResource: ofType:inDirectory:

I have a file paylines.txt added inside the folder named TextFiles which resides inside the Resources folder of my iOS project in Xcode. This is the code I use to access the file: NSString* filePath = [[NSBundle mainBundle]…
Yadnesh
  • 1,307
  • 3
  • 17
  • 36
43
votes
8 answers

core data in a static library for the iPhone

I've built a static library that makes heavy use of the Core Data framework. I can successfully use the library in my external project, but ONLY if I include the .xcdatamodel file in the main project. That is less than ideal, since the point of the…
Vik
  • 1,301
  • 4
  • 16
  • 29
39
votes
10 answers

NSBundle pathForResource is NULL

I'm creating a simple application with xcode and objc and I need to load an NSDictionary from a file, but I can't get the path to the file using NSBundle: NSString *l = [[NSBundle mainBundle] pathForResource:@"LoginStatuses"…
patrick
  • 6,533
  • 7
  • 45
  • 66
39
votes
1 answer

OCUnit & NSBundle

I created OCUnit test in concordance with "iPhone Development Guide". Here is the class I want to test: // myClass.h #import #import @interface myClass : NSObject { UIImage *image; } @property…
kpower
  • 3,871
  • 4
  • 42
  • 62
38
votes
6 answers

How to get bundle for a struct?

In Swift, you can call let bundle = NSBundle(forClass: self.dynamicType) in any class and get the current bundle. If you NSBundle.mainBundle() this will fail getting correct bundle when for example running unit tests. So how can you get the…
bogen
  • 9,954
  • 9
  • 50
  • 89
37
votes
1 answer

Swift - Get NSBundle for test target?

In Objective C whenever I had to access the test bundle I would call [NSBundle bundleForClass:[ClassInTestTarget class]]; bundleForClass is not available in Swift, so how do I access the test bundle? The reason I need this is that in order to write…
aryaxt
  • 76,198
  • 92
  • 293
  • 442
1
2 3
37 38