I have successfully created an app that reads from a bundled .plist file and displays the contents in a UITableView. I would like to move that plist to an external site, as it is updated frequently. even better, I would love to have it generated with PHP. I have got the server side working, but the Objective C is giving me a headache…
My code used to read like this:
NSString *myfile = [[NSBundle mainBundle] pathForResource:@"notices" ofType:@"plist"];
according to various google searches, my code should now look something like this:
NSString *myfile = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"http://localhost/plistgen1.php"]];
Obviously this is not going to work, mixing NSString with NSDictionary, but I have tried (and failed) to get it to work properly. does anyone have a solution, or a different way to approach the problem? The data I am using is on a mysql server, and the plistgen1.php just “fills in the blanks” in the plist file and echoes it out…
I may have got this all wrong, don’t shoot me 🙂
The first case (“My code used to read like this”) gives you the local filesystem path to the bundled plist file and saves it to the variable
myfile. In the second case you’re downloading the plist file’s contents from the server and creating a dictionary from that.You probably have some code after the assignment of the file path to
myfilethat reads the contents of that file into anNSDictionary. You need to replace both the assignment tomyfileand that statement with the second example.So you’d replace something like this:
With this: