nsbundle

Swift - Get NSBundle for test target?

不羁的心 提交于 2019-12-03 10:46:17
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 tests for a framework I'm working on I have to use an in memory core data stack. Initially all resources were included in both main target and test target, but then I moved all these test helpers to test target only, and now the code below is returning nil which fails all my tests let modelURL = NSBundle.mainBundle().URLForResource("Model",

How to get bundle ID?

做~自己de王妃 提交于 2019-12-03 10:30:14
问题 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 this information, or is it held in a plist somewhere. I am not using the default bundle id, I remember setting it while I created the project. 回答1: If you are trying to get it programmatically , you can use below line of code : objective C NSString

How to use Core Data's ManagedObjectModel inside a framework?

落爺英雄遲暮 提交于 2019-12-03 09:31:16
I'm trying to migrate a specific part of one of my apps into a framework so that I can use it in my app itself and in one of those fancy new iOS 8 widgets. This part is the one that handles all my data in Core Data. It's pretty straight forward to move everything over and to access it. I'm just having trouble accessing my momd file in there. When creating the NSManagedObjectModel I still try to load the momd as illustrated in Apple's code templates: NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"MyApp" withExtension:@"momd"]; __managedObjectModel = [[NSManagedObjectModel alloc]

Swift - read plist file to an array?

ⅰ亾dé卋堺 提交于 2019-12-03 07:31:56
I have created a mini translation from English words to Spanish words. I would like to use the englishArray.plist instead of my englishArray = ["the cat"] How can I create this? I have also used a localizable.strings to retrieve the value "the cat" for "el gato" but I would like to retrieve this from englishArray.plist I started off with this but not sure if I'm on the right path let path = NSBundle.mainBundle().pathForResource("englishArray", ofType: "plist") let plistEnglishArray = NSArray(contentsOfFile: path!) Here is the rest of my code: var englishArray: [String] = ["rainbow", "boots",

Load files in xcode unit tests

爷,独闯天下 提交于 2019-12-03 07:20:54
问题 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 dataWithContentsOfFile:@"TestResource/TestData.xml"]; NSString* fileString = [NSString stringWithContentsOfFile:@"TestData.xml" encoding:NSUTF8StringEncoding error:&error]; Also if I try to preview all the bundles using [NSBundle allBundles] the unit test bundle does not appear

How to check if a Storyboard exists in a specific NSBundle

折月煮酒 提交于 2019-12-03 06:27:28
I'm making an app that makes use of a framework that I'm creating. The framework contains storyboards but in some cases the project making use of the framework will need to override the storyboard by providing a new one. So my goal is to check if a storyboard with a given name exists in [NSBundle mainBundle] , if not then I will get the base version from my framework. I have tried getting the storyboard from the main bundle and checking for the result being nil but it throws an exception if it can't find it. So I then tried to catch the exception and then load the storyboard from the framework

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

人盡茶涼 提交于 2019-12-03 06:13:36
问题 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 can't figure out how to check if the file exists there in the first place. Regards Dave 回答1: [[NSFileManager defaultManager] fileExistsAtPath:pathAndFileName]; 回答2: This code worked for me... NSString *pathAndFileName = [[NSBundle mainBundle]

Get resource URL from project specific path

我怕爱的太早我们不能终老 提交于 2019-12-03 05:53:14
I need to retrieve the URL of a resource contained in my Xcode project through a path that begins in the project's directory (aka mainBundle) So if my specified path if ./snd/archer/acknowledge1.wav, I need to create a URL from that. I know I can use NSURL(fileURLWithPath:) for system directories, but I don't know how to do this directly from the bundle. Wain You would use one of the bundle resourse URL methods [[NSBundle mainBundle] URLForResource:@"acknowledge1" withExtension:@"wav" subdirectory:@"snd/archer"]; NSBundle.mainBundle().URLForResource("acknowledge1", withExtension:"wav"

NSBundle pathForResource returns nil with subdirs

邮差的信 提交于 2019-12-03 05:48:43
I have a bunch of directories and files in my app, for instance images/misc/mainmenu_background. . I'm running the following code in the "iPad Simulator 3.2": NSString *images = [[NSBundle mainBundle] pathForResource:@"images" ofType:nil]; NSString *images_misc = [[NSBundle mainBundle] pathForResource:@"images/misc" ofType:nil]; NSString *images_misc_file = [[NSBundle mainBundle] pathForResource:@"images/misc/mainmenu_background.png" ofType:nil]; After this call, images contains the path /Users/wic/Library/Application Support/iPhone Simulator/3.2/Applications/8F67150B-71E6-4735-8CC6

Using XIB/NIB files contained within downloaded bundles on iOS

。_饼干妹妹 提交于 2019-12-03 05:09:51
On the face of it, this seems a very simple problem but for some reason I can't quite get it to work. I have a magazine-style app that downloads the data for each issue in the form of a zipped bundle. Once downloaded, and unpacked, the app successfully accesses the various files contained within the bundle as expected. These include JSON, PNG, JPG, video and so on. However, I also included a XIB file that contains the physical layout of the content in a series of UIViews and it is this file that I cannot use. The file is present but when I try and load it using: UIViewController *controller =