Using iOS SDK to create a plist at runtime?

后端 未结 3 772
再見小時候
再見小時候 2021-02-06 17:59

I am new to iPhone development. I want to know if there is any sample Objective-C code to create a plist at runtimeby getting data from a webserver and I want to know what the f

3条回答
  •  不要未来只要你来
    2021-02-06 18:03

    Plist files are mainly used by Mac OS X to store serialized objects in a key/value manner. There are multiple kinds of Property List files; ASCII, XML and Binary.So in your case your server should send the data in xml format.After receiving the data from server you can generate plist at runtime. You can use the below code to write data in .plist file.

    - (void)writeToPlist{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"WebData.plist"];
    NSArray *dataToSave = [dataToSave writeToFile:filePath atomically:YES];
    }
    

    Please refer this and these links for server side also link1 link2 link3 link4.

提交回复
热议问题