nsbundle

NSBundle pathForResource is NULL

谁都会走 提交于 2019-11-26 09:35:49
问题 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: 回答1: So here's the solution for this problem

core data in a static library for the iPhone

别等时光非礼了梦想. 提交于 2019-11-26 09:05:49
问题 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

Access Asset Catalog pathForResource

淺唱寂寞╮ 提交于 2019-11-26 07:36:02
问题 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? 回答1: Same problem,

Write a file on iOS

强颜欢笑 提交于 2019-11-26 03:07:41
问题 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