Plist data is an apple-created data format, based on XML, which is often used because it is very convenient to operate plist in a IOS,MAC system. In an iOS project, a info.plist file is automatically generated that contains some configuration information for the iOS project. The root node type of the Plist file can be either a dictionary dictionary or an array of arrays.
。
Now we try to create a new plist array and parse it ourselves. The specific implementation is as follows:
(1) Under the project directory supporting files, under new files, then select Property list in the popup dialog box. Enter a name, and a plist file will be generated.
(2) The plist file has 3 parts, namely the key, type, value. Where the root root node can only select an array or dictionary, the data type of the other child nodes can be boolean,date,data,number,string. If you select array, this means that this is an plist array, or if you select dictionary, this means a plist dictionary. Let's first select array, then insert some data inside,
。
(3) Then in the Viewcontroller code implemented as follows, for plist array parsing, output:
Import Uikitclass Viewcontroller:uiviewcontroller { override func Viewdidload () { super.viewdidload () var array = Nsarray (Contentsofurl:nsurl (FileURLWithPath:NSBundle.mainBundle (). Pathforresource ("Data", OfType: " Plist ") !!)! For index in array{ println (Index)}}}
The output results are as follows:
。
The plist array has been successfully read and parsed and stored in a normal array format. So that we can easily operate the plist file.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
iOS project development Combat--plist Array Parsing