English 中文(简体)
页: 1 Dictionary initWithContentsOfFile - Fal
原标题:NSMutableDictionary initWithContentsOfFile - null
  • 时间:2012-05-09 12:08:47
  •  标签:
  • iphone
  • ios

我试图建立一个带有清单内容的国家安全局。 我有以下法典:

NSString *myFile = [[NSBundle mainBundle] pathForResource:@"words" ofType:@"plist"];
NSMutableDictionary* myDict = [[NSMutableDictionary alloc]initWithContentsOfFile:myFile];
NSObject *randomWord = [myDict objectForKey:@"Item 6"];
NSLog(@"%@", randomWord);

我的碎片和左部已经填满(并非完全无效),但是,如果想要印刷随机的散射(或有关这个问题的神话),它就印刷了“(核心)”。

我在任何地方都看着。 我做了什么错误?

Edit:

self    MainViewController *const   0x068c0d60
myDict  NSMutableDictionary *   0x0000586c
myFile  NSString *  0x068c31f0

安保部

2012-05-10 12:26:22.302 project2[681:f803] (null)

因此,我方言和我的分歧似乎已经填满,但随机放火吗?

Edit #:

缩略语

2012-05-10 14:15:17.016 project2[2641:f803] (null)

因此,你认为,我的分歧是空洞的。

问题回答

第6项

[myDict objectForKey:@"Item6"];

如果没有尝试,

NSString *path = [[NSBundle mainBundle] pathForResource:@"words" ofType:@"plist"];
NSData* data = [NSData dataWithContentsOfFile:path];
NSMutableArray* array = [NSPropertyListSerialization propertyListFromData:data
                                                         mutabilityOption:NSPropertyListImmutable
                                                                   format:NSPropertyListXMLFormat_v1_0
                                                         errorDescription:NULL];
if (array) {
  NSMutableDictionary* myDict = [NSMutableDictionary dictionaryWithCapacity:[array count]];
  for (NSDictionary* dict in array) {
    State* state = [[State alloc] initWithDictionary:dict];
    [myDict setObject:state forKey:state.name;
    [state release];
  }
  NSLog(@"The count: %i", [myDic count]);
} else {
  NSLog(@"Plist does not exist");
}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签