nsbundle

iPhone : Get the file path which is within subfolder of Resource folder

倾然丶 夕夏残阳落幕 提交于 2019-11-27 02:28:11
问题 I am new to iPhone programming. I want to read the content of a text file located in a subfolder of the Resource folder. The Resource folder structure is the following: Resource Folder1---->Data.txt Folder2---->Data.txt Folder3---->Folder1---->Data.txt There are multiple files named "Data.txt", so how can I access the files in each folder? I know how to read the text file, but if the Resource structure is similar to the above structure then how can I get the path? For example, if I want to

Working with paths from [[NSBundle mainBundle] resourcePath]

假如想象 提交于 2019-11-27 01:36:54
问题 I'm sure it's a very basic problem, but I'm having trouble finding anything about it. Say I've got my app in a folder, in some more folders, like this: MainFolder > SecondaryFolder > AppBundle.app > all the stuff Then, what I want to do is access a file that is in the "MainFolder". I know I can get the path of the AppBundle by using: NSLog(@"%@",[[NSBundle mainBundle] resourcePath]); What I'm uncertain about is how to get the path of the "MainFolder". Any pointers would be great! Thanks, Tom

NSBundle pathForResource is NULL

强颜欢笑 提交于 2019-11-27 00:59:31
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" ofType:@"plist"]; NSLog(@"%@", l); When I run this code I get this: 2010-10-16 10:42:42.42 Sample[5226:a0f] (null) And I don't know why. I created a group called Resources and there I added the LogingStatuses.plist: So here's the solution for this problem after I got the source: I didn't really pay attention to the posted screenshot, but the target is of type " Command

UIImage imageNamed requires pathForResource?

时光毁灭记忆、已成空白 提交于 2019-11-26 22:17:01
问题 How necessary is it to search for a path to an image using the NSBundle method pathForResource when creating a UIImage using imageNamed ? I see tutorial codes that just specifies the name of the image directly, and then code that goes the extra mile to find the path first. In my experience, I've always just used the name directly and it's always worked fine. I assumed that it automatically knew how to find the image. How important or under what circumstances would it be necessary to do more

core data in a static library for the iPhone

天涯浪子 提交于 2019-11-26 21:24:02
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 library was to hide implementation details to the maximum possible. In a separate question , I was informed that I cannot bundle resources with a library (which makes complete sense to me now). So is there a way to programatically allow the model to be 'discovered' without having to include the model in the main project? I also created my own static

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

假装没事ソ 提交于 2019-11-26 21:16:12
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 pathForResource: returns nil, meaning it could not locate foo.txt . I've made sure that foo.txt is included in the Copy Bundle Resources build phase of the unit test target, so why can't it find the file? benzado When the unit test harness runs your code, your unit test bundle is NOT the main bundle. Even though you are running tests, not your application

Access Asset Catalog pathForResource

时光毁灭记忆、已成空白 提交于 2019-11-26 20:25:40
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" inDirectory:@"Images"]; [[NSBundle mainBundle] pathForResource:@"name" ofType:@"png" inDirectory:@"Images.xcassets"]; But neither of those worked either. Has anyone had success retrieving paths to assets in the catalog? sunnyxx Same problem, but I don't think we could access it via pathForResource: , except below: UIImage* image = [UIImage imageNamed:@

loading NSBundle files on iOS

最后都变了- 提交于 2019-11-26 18:54:12
问题 I'd like to create a project that has a very flexible graphical user interface ( skinnable ). In order to make this possible, I'd like to load a NSBundle from an external resource, e.g. a website. The bundle should contain nibs that correspond to some properties and methods in the main project (IBOutlets & IBActions) It seems Apple has limited the possibility to use NSBundle in such a way. Is there any way I can make this work? If it's not possible in the conventional way, what would be a

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

老子叫甜甜 提交于 2019-11-26 15:18:29
问题 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] pathForResource:@"paylines" ofType:@"txt" inDirectory:@"TextFiles"]; NSLog(@"\n\nthe string %@",filePath); The code prints: 2011-06-07 14:47:16.251 slots2[708:207] the string (null) 回答1: I was also having the same problem. The Solution i found is ( in xcode 4.x): Go to :

Write a file on iOS

╄→尐↘猪︶ㄣ 提交于 2019-11-26 12:50:44
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 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"MyFile"]; [data writeToFile:appFile atomically:YES]; I have created MyFile.txt on resources. saadnib Your code is working at my end, i have just tested it. Where are you checking your