nsbundle

Best way of loading images from application bundle

妖精的绣舞 提交于 2019-12-03 05:09:01
What is the best way of loading images from the application main bundle. I am using [UIImage imageNamed: "image.png"]; But I have heard that this is not good in terms of memory usage and performance. Can anyone please give his/her feedback on it? My application reads lots of images from main bundle at launch time. I want to make this process as efficient as possible. Best Regards UIAdam If you want to try loading the images without caching, you can use: [[UIImage alloc] initWithContentsOfFile:@"image.png"]; This could be slightly faster loading the image for the first time, since it doesn't

iPhone/iPad: Unable to copy folder from NSBundle to NSDocumentDirectory

自古美人都是妖i 提交于 2019-12-03 03:57:02
I am trying to copy a folder in my NSBundle which contains quite a number of images. I tried doing it with these codes. NSFileManager *fileManager = [NSFileManager defaultManager]; NSError *error; NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *documentDBFolderPath = [documentsDirectory stringByAppendingPathComponent:@"Images"]; NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Images"]; [fileManager copyItemAtPath

Overriding preferred strings localization on the fly for testing

夙愿已清 提交于 2019-12-03 03:51:37
Using the Settings app in the iPhone simulator to switch languages is a PITA way of testing localization tweaks. I'm trying to figure out a way to switch localizations (en/fr/es/etc) on the fly in my app with a debug setting without restarting the app. NSBundle provides ways of requesting localized resources from an arbitrary localization, e.g. - (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension inDirectory:(NSString *)subpath forLocalization:(NSString *)localizationName But I find no equivalent for the string management subsystem. It sounds from these questions that

Could not find a storyboard named 'Main' in bundle NSBundle

旧巷老猫 提交于 2019-12-03 02:55:21
during the progress of my app I decided to change from using a UIStoryboard to .xib file, and now I get the error: Could not find a storyboard named 'Main' in bundle NSBundle How can I fix this problem within the Simulator part of my app? Remove the "Main storyboard file base name" or "UIMainStoryboardFile" Key from your info.plist file. Click Your Story board then do step 2 and step 3 来源: https://stackoverflow.com/questions/25739477/could-not-find-a-storyboard-named-main-in-bundle-nsbundle

How to get bundle ID?

风格不统一 提交于 2019-12-03 01:02:24
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. Aks If you are trying to get it programmatically , you can use below line of code : objective C NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier]; Swift 3.0 : let bundleIdentifier = Bundle

Load files in xcode unit tests

我只是一个虾纸丫 提交于 2019-12-02 19:55:55
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 in the list? I tried to create a separate resource bundle and I can't seem to locate it

What is NSBundle and mainBundle in objective C?

孤街醉人 提交于 2019-12-02 18:57:46
I want to ask a question about the objective C on iPhone application. I read some sample program in the apple developer website and I found that almost all of the applications contains a word called 'NSBundle' and 'mainBundle', and I really don't understand the meaning of this word. Can anyone tell me about that? Thank you very much. JeremyP A bundle is a structure used for packaging software on Mac OS X. Applications, frameworks and plug-ins are all different kinds of bundles. Bundles may contain executable code, resources, header files and other stuff (including other bundles) if you so wish

Can't read from plist

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 12:08:09
问题 I'm trying to do something that I already know how to do - but it isn't working. Looking for ideas to fix this. I think it's something to do with the way Xcode 4.1 creates plist files. I'm trying to read strings from a plist file, and dump them into an NSArray. This is my code: NSString *myFile = [[NSBundle mainBundle] pathForResource:@"File1"ofType:@"plist"]; myArray = [[NSArray alloc]initWithContentsOfFile: myFile]; I created a plist file in Xcode - an array at the top level and a few

Checking the presence of a file in the bundle

♀尐吖头ヾ 提交于 2019-12-01 10:52:57
How can we check if a file is present in the external bundle loaded in the app or not before fetching it? If you only want to know if it's there so you can decide whether to load it or not, I'd just attempt to load it and check if the object returned is nil. If it is, you know it doesnt exist in the bundle. To check if a file exists in the bundle, use the NSBundle class. NSString *path = [[NSBundle mainBundle] pathForResource:@"somefileinbundle" ofType:@"png"]; if (!path) NSLog(@"Unable to find file in bundle"); Having said that however, it's typically a bad idea to check if a file exists

Replacing images in the bundle at run time

喜欢而已 提交于 2019-12-01 09:30:23
Can I replace images in bundle at run time? Basically, I have some images part of my bundle and also I will have them from the server if there is any change in the image. Can I place them in the bundle at run time so that I need not to change my code to pick the image? You cannot change the contents of an Application bundle. It is however possible to store the images in the Application's documents folder. Then you'll be able to overwrite those images in case they need to be changed. There are two ways to achieve this: At launch, check whether the image files exist in the documents directory.