nsbundle

OCUnit & NSBundle

隐身守侯 提交于 2019-11-30 01:18:09
I created OCUnit test in concordance with "iPhone Development Guide". Here is the class I want to test: // myClass.h #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface myClass : NSObject { UIImage *image; } @property (readonly) UIImage *image; - (id)initWithIndex:(NSUInteger)aIndex; @end // myClass.m #import "myClass.m" @implementation myClass @synthesize image; - (id)init { return [self initWithIndex:0]; } - (id)initWithIndex:(NSUInteger)aIndex { if ((self = [super init])) { NSString *name = [[NSString alloc] initWithFormat:@"image_%i", aIndex]; NSString *path = [[NSBundle

Getting bundle file references / paths at app launch

别说谁变了你拦得住时间么 提交于 2019-11-30 00:12:43
问题 Suppose I have an arbitrary set of files included in the Main App Bundle. I would like to fetch the file URLs for those at launch and store them somewhere. Is this possible using NSFileManager ? The documentation is unclear in that regard. Note: I only need the file URLs, I do not need to access the actual files. 回答1: You can get the URL of a file in the main bundle using NSString *path = [[NSBundle mainBundle] pathForResource:@"SomeFile" ofType:@"jpeg"]; NSURL *url = [NSURL fileURLWithPath

NSURL to file path in test bundle with XCTest

倾然丶 夕夏残阳落幕 提交于 2019-11-29 22:37:16
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) fetchAndStoreImage:(NSURL *)imageUrl I'm trying to write the test for this method in a way that it doesn't fail if there is no connection to the internet. My approach (taken from a previous question ) is to call the method using a NSURL to an image in the local file system. When a new project with unit tests enabled is created, the Tests directory has a

Get fileSize of info.plist to prevent piracy

冷暖自知 提交于 2019-11-29 20:31:34
I'm trying to put anti-piracy code in my app. The previous answer to this (which I can't link to because of my member status - sucks) can be easily countered, since the "SignerIdentity" string can be looked for and replaced in the binary using a hex editor. Instead, checking the fileSize of the info.plist file and comparing it to a reference value sounds more solid (since the info.plist is getting modified here and there when cracking the app). How would I do that? I tried the following but it logs 0. NSBundle *bundle = [NSBundle mainBundle]; NSDictionary *mainDictionary = [bundle

NSBundle, plist and other resources in an Obj-c Static Library

做~自己de王妃 提交于 2019-11-29 20:29:31
I've created a static library in Xcode, which I am able to successfully use in other projects. However, with resources like plists, I find I must include any plists referenced in my library in the main project where the project is used. In my static library project, I have my plist included in the "Copy Bundle Resources" phase of the target. In my code, here is what I am doing: NSBundle *mainBundle = [NSBundle mainBundle]; NSString *filePath = [mainBundle pathForResource:@"MyClassParams" ofType:@"plist"]; NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithContentsOfFile

How to get path to a subfolder in main bundle?

半世苍凉 提交于 2019-11-29 13:59:27
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. dasblinkenlight In Swift-3 make URL , and call appendingPathComponent : let resourcePath = Bundle.main.resourcePath let subdir = URL(fileURLWithPath:resourcePath!)

Get file path by file name from documents directory ios

偶尔善良 提交于 2019-11-28 19:33:18
In my application I download PDF files which gets stored in "Document" directory under different sub folders. Now I have file name for which I want to get its path in "Document" directory but problem is I don't know the exact sub folder under which that file is stored. So is there any method which will give me file path by file's name like there is one method which works for main bundle: (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension I don't want to iterate through each folder which is a tedious way. Thanks. Abhi Beckert You can search the documents directory like

NSURL to file path in test bundle with XCTest

只谈情不闲聊 提交于 2019-11-28 17:19:17
问题 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) fetchAndStoreImage:(NSURL *)imageUrl I'm trying to write the test for this method in a way that it doesn't fail if there is no connection to the internet. My approach (taken from a previous question) is to call the method using a NSURL to an image in the

NSBundle, plist and other resources in an Obj-c Static Library

青春壹個敷衍的年華 提交于 2019-11-28 17:08:43
问题 I've created a static library in Xcode, which I am able to successfully use in other projects. However, with resources like plists, I find I must include any plists referenced in my library in the main project where the project is used. In my static library project, I have my plist included in the "Copy Bundle Resources" phase of the target. In my code, here is what I am doing: NSBundle *mainBundle = [NSBundle mainBundle]; NSString *filePath = [mainBundle pathForResource:@"MyClassParams"

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

不问归期 提交于 2019-11-28 09:52:00
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 and a half without an interface that works. How should I proceed? Ralph Willgoss I got the following