Can't read from plist

前端 未结 2 2025
别跟我提以往
别跟我提以往 2021-01-16 20:42

I\'m trying to do something that I already know how to do - but it isn\'t working. Looking for ideas to fix this. I think it\'s something to do with the way Xcode 4.1 create

2条回答
  •  轮回少年
    2021-01-16 21:06

    If you just want the plist loaded, you need to use property list serialization to first load the plist as NSData

    [[NSData alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"File1"]]
    

    then serialize it into a dict (or array, depending on what your root item is) using

    NSDictionary *aDict = [NSPropertyListSerialization propertyListWithData: options: format: error:]
    

    When you view the plist in Xcode, the top level element is the type to make aDict.

    See here for more info: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/PropertyLists/SerializePlist/SerializePlist.html

    If you want the entire plist loaded as strings, you probably need to do something with an NSString method, something like [NSString stringFromData].

提交回复
热议问题