How to read data structure from .plist file into NSArray

后端 未结 8 801
故里飘歌
故里飘歌 2020-11-28 20:15

I was creating a data structure manually using the following:

NSDictionary* league1 = [[NSDictionary alloc] initWithObjectsAndKeys: @\"Barclays Premier Leagu         


        
相关标签:
8条回答
  • 2020-11-28 20:51

    This Code is working

    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"plist-name" ofType:@"plist"];
    NSDictionary *Dictionary= [[NSDictionary alloc]initWithContentsOfFile:plistPath];
    NSLog(@" current version CFBundleVersion = %@",[Dictionary valueForKey:@"CFBundleVersion"]);
    
    0 讨论(0)
  • 2020-11-28 20:52

    If the file is not added in the resources folder and only placed in your documents directory. You can do this

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"file.plist"];
    NSMutableArray *arrContentsplist = [[NSMutableArray alloc] initWithContentsOfFile:path];
    
    0 讨论(0)
提交回复
热议问题