Day01-ios (Plist)

Source: Internet
Author: User

The path to iOS has finally started, and with M A J video Tutorial step-by-step, will add to their new things.

=====TOPIC01 Why would---Use the plist file??? =======

It is not a reasonable practice to directly write data directly into the code. If the data is often changed, it is necessary to turn over the corresponding code to modify, resulting in low code extensibility, so you can consider to put the frequently changed data in the file for storage, the program starts to read the latest data from the file. If you want to change the data, directly modify the data file, without modifying the code can generally use the property list file to store Nsarray or nsdictionary, such as data, this property list file extension is plist, so also become "plist file"

--------------------------------------------------

Parsing data in a plist file

STEP01: Get the full path to the plist file

NSBundle *bundle = [NSBundle mainbundle];//What the bundle this is on the mobile hardware side looking for the main file store!

NSString *path = [Bundle pathforresource:@ "ImageData" oftype:@ "plist"];

STEP02: Loading plist files

_images = [Nsarray Arraywithcontentsoffile:path];

-(Nsarray *) images

{

if (_images = = nil) {

NSBundle *bundle = [NSBundle mainbundle];

NSString *path = [Bundle pathforresource:@ "ImageData" oftype:@ "plist"];

_images = [Nsarray Arraywithcontentsoffile:path];

}

return _images;

}

Day01-ios (Plist)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.