nsbundle

How to get path to a subfolder in main bundle?

牧云@^-^@ 提交于 2019-11-28 07:34:50
问题 I have a project which I am migrating from Obj-C to Swift 3.0 (and I am quite a noob in Swift). How do I translate this line? NSString *folder = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myfolder"]; I managed to get resource path: let resoursePath = Bundle.main.resoursePath; But how do I get path to a subfolder named "myfolder"? I need to get a path the subfolder, not path to the files inside it. 回答1: In Swift-3 make URL , and call appendingPathComponent : let

Working with paths from [[NSBundle mainBundle] resourcePath]

∥☆過路亽.° 提交于 2019-11-28 06:55:39
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 I'd use -[NSString stringByDeletingLastPathComponent] twice. NSString *bundlePath = [[NSBundle

arrayWithContentsOfFile can't read plist file

喜欢而已 提交于 2019-11-28 04:04:51
问题 i have a plist with an array that contain 2 strings see image : http://imageshack.us/photo/my-images/263/myplist.png/ and in my viewDidLoad i add this : NSString *file = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"]; NSArray *array = [NSArray arrayWithContentsOfFile:file]; NSLog(@"array = %@", array); But i got always null why? Thanks for help. UPDATE : the solution is that you need to manually edit the plist file (Xcode4 use Dictionnary by default) <?xml version="1.0"

loading NSBundle files on iOS

我与影子孤独终老i 提交于 2019-11-27 17:05:21
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 recommendable alternate approach? untested. You can distribute all the content in a zip file, unzip using

How to get the current application icon in ios

烂漫一生 提交于 2019-11-27 13:41:43
问题 Is there a way to get the current application icon in a cocoa-touch app? Thank you. 回答1: Works for Swift 4.1 and extending it for Bundle. extension Bundle { public var icon: UIImage? { if let icons = infoDictionary?["CFBundleIcons"] as? [String: Any], let primaryIcon = icons["CFBundlePrimaryIcon"] as? [String: Any], let iconFiles = primaryIcon["CFBundleIconFiles"] as? [String], let lastIcon = iconFiles.last { return UIImage(named: lastIcon) } return nil } } To use in an app, call Bundle.main

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

送分小仙女□ 提交于 2019-11-27 10:44:30
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) I was also having the same problem. The Solution i found is ( in xcode 4.x): Go to : Target -> "Build Phases" -> "copy bundle Resources" Then add that particular file here. If that file is

UIImage imageNamed requires pathForResource?

十年热恋 提交于 2019-11-27 07:53:00
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 than this? The docs say that “the method looks for an image with the specified name in the application’s

NSBundle pathForResource returns nil

守給你的承諾、 提交于 2019-11-27 06:43:16
问题 I've been trying to load a simple text file in a unit test for an iOS app. NSString* resourcePath = [[NSBundle mainBundle] pathForResource: @"stopPointsInCircleData" ofType:@"txt"]; NSString* stopPointData = [NSData dataWithContentsOfFile: resourcePath]; My problem is that pathForResource returns nil. The file stopPointsInCircleData.txt is located in the directory of the test code and the file is listed correctly under "Copy Bundle Resources" in the "Build Phases" of the test target. I've

UIWebView to Play Local and downloaded Video

99封情书 提交于 2019-11-27 06:25:58
问题 I want to play downloaded video using UIWebview. I get webkiterrordomain code=204 error. but if i play video from resources folder it run perfect. //from resources folder run perfect NSString *tempurl = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"video.mp4"]; //from downloaded file NSString *tempurl = downloaded path; NSURL* urlLocation = [NSURL fileURLWithPath:tempurl]; [webView loadRequest:[NSURLRequest requestWithURL:urlLocation]]; Thank you. 回答1: Solution is

XCode deployment error: 'NSInvalidArgumentException', Could not find a storyboard named 'MainStoryboard'

一个人想着一个人 提交于 2019-11-27 03:16:29
问题 Like many of the prior 'MainStoryboard missing in NSBundle' questions, I've got the same prompt but have found no issue with naming and no issue with if the storyboard exists within an area XCode likes. All the pointers lead to the same file, I've changed my .plist a good 5 times to make it responsive to the same call as found in Build Stages. Now I'm all kinds of tired of this crap because I just want to program, not debug compiler screw ups. It happened in an instant and now I've been a day