core data in a static library for the iPhone

Sascha’s answer got me on the right track. Merging a compiled .mom file from a static library into the .mom file from a host project was relatively simple. Here’s a trivial example: Create a new XCode Static Library project called MyStaticLibrary Create an .xcdatamodel file in MyStaticLibrary called MyStaticLibraryModels.xcdatamodel, add some Entitys, then generate the … Read more

How to get bundle ID?

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.main.bundleIdentifier It will work for both iOS and Mac apps Good luck..

Access Asset Catalog pathForResource

Same problem, but I don’t think we could access it via pathForResource:, except below: UIImage* image = [UIImage imageNamed:@”name-in-asset-catalog”]; It has been clearly documented: Each set in an asset catalog has a name. You can use that name to programmatically load any individual image contained in the set. To load an image, call the UIImage:imageNamed: … Read more

Load files in xcode unit tests

When running tests the application bundle is still the main bundle. You need to use unit tests bundle. Objective C: NSBundle *bundle = [NSBundle bundleForClass:[self class]]; NSString *path = [bundle pathForResource:@”TestData” ofType:@”xml”]; NSData *xmlData = [NSData dataWithContentsOfFile:path]; Swift 2: let bundle = NSBundle(forClass: self.dynamicType) let path = bundle.pathForResource(“TestData”, ofType: “xml”)! let xmlData = NSData(contentsOfFile: path) … Read more

Write a file on iOS

May be this is useful to you. //Method writes a string to a text file -(void) writeToTextFile{ //get the documents directory: NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; //make a file name to write the data to using the documents directory: NSString *fileName = [NSString stringWithFormat:@”%@/textfile.txt”, documentsDirectory]; //create content – … Read more

NSURL to file path in test bundle with XCTest

In fact, the [NSBundle mainBundle] when running a UnitTest is not the path of your app, but is /Developer/usr/bin, so this will not work. The way to get resources in a unit test is here: OCUnit & NSBundle In short, use: [[NSBundle bundleForClass:[self class]] resourcePath] or in your case: [[NSBundle bundleForClass:[self class]] resourceURL]

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)