Loading a .plist file from url

瘦欲@ 提交于 2019-12-04 21:28:51

I suggest looking into using Json. It will allow you to pass plist like structured data from a url to your app.

NSData *dataReturn = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://someUrl.com/test.json"]];

    if (dataReturn) {
        NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:dataReturn options:kNilOptions error:Nil];

If you want to use your plist then its just about the same code:

// This will get the plist into data format
NSData *dataReturn = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://someUrl.com/test.plist"]];

// This will convert data format to array
NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:dataReturn]
Zer0_byt3

In the end I managed to do what I needed using just this simple piece of code:

NSMutableArray *tmpArray = [[NSMutableArray alloc]initWithContentsOfURL:[NSURL URLWithString:@"http://zer0soft.altervista.org/AnimeDB.plist"]];    
self.dataList1 = tmpArray; 

And it works like a charm! Thanks to everyone who spent time answering my question, in particular thanks to Jaybit!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!