How to make plist and read data from plist in cocos2d-x

Depending on the conditions,if it is required to store small piece of data(mostly when tabular) and to retrieve that data in your project,then it is not wise to use sqlite,plist is best to use conditionally.

For making and add data to plist,just go to ios folder in your project,right click and select new file option,window will appear,then select resource option and click on property list,window then looks to you as following:

Screen Shot 2014-06-25 at 12.52.46 PM

Click Next and name the plist file and click on create,your plist is created.Now open your plist and add the data to the file

For the Root folder,select Array from type(you can select any option) and click on + sign,1 data is created,you can select any type of the data,here i am selecting dictionary,open the data and add the items to a dictionary and add the corresponding values to them.Similarly you can add other data to the root folder,and it will look as:

Screen Shot 2014-06-25 at 5.35.58 PM

Now your plist is ready to retrieve.

For retrieving the data from the plist,use the following code:

this above function will return one value at a time for the array index and for the corresponding item.For calling this function,we use the following code line.Example we want to retrieve the value for 3_star for the 1st index,then we will call as:

Here we are getting all the values in the array “arr” in the above function,we can modify the array as per our requirement.

2,628 total views, 2 views today

Share this OnShare on FacebookTweet about this on TwitterShare on LinkedInShare on Google+

Leave a Reply