Plist文件的操作
2015-11-22 10:12
411 查看
plist文件是苹果自带的配置文件 主要是以xml的格式进行匹配的
创建的时候 选择resource的plist来进行创建 他主要有两种类型 一种是字典类型的 还有一种是数组类型的
可以通过添加子元素来进行创建
通过数组来解析plist文件 将plist文件解析后,保存在一个数组中,随后将其输出即可 此时的plist文件一定要是数组类型的 否则无法输出
字典的解析 同样的道理 此时的plist文件也必须是字典类型的否则也无法输出 数据类型就是文章开始创建的data.plist文件
创建的时候 选择resource的plist来进行创建 他主要有两种类型 一种是字典类型的 还有一种是数组类型的
可以通过添加子元素来进行创建
通过数组来解析plist文件 将plist文件解析后,保存在一个数组中,随后将其输出即可 此时的plist文件一定要是数组类型的 否则无法输出
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. //通过数组来进行解析 let arr = NSArray(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("data", ofType: "plist")!)) //输出数组 if let a = arr { print(a) } else { print("nil") } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
字典的解析 同样的道理 此时的plist文件也必须是字典类型的否则也无法输出 数据类型就是文章开始创建的data.plist文件
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. //通过字典来进行解析 let dict = NSDictionary(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("data", ofType: "plist")!)) //输出字典 if let dict1 = dict{ print(dict1) //输出字典的name属性所对应的值 var name = dict1["name"] print("name: \(name!)") } else { print("nil") } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
相关文章推荐
- 初入iOS自学问题笔记
- sql无法启动MSSQLSERVER,报错17051
- myEclipse中配置maven
- 配置IIS7支持解析json文件
- bootStrap table+ajax加载数据
- 利用MATLAB画一些简单图形
- picasso vs UIL
- 26.c/c++程序员面试宝典-访问控制
- Win7-其中的文件夹或文件已在另一个程序中打开
- Tomcat中JVM内存溢出及合理配置
- Qt 改变形状的对话框
- Java static关键字总结
- Linux下编译的第一个程序
- 【郝斌数据结构自学笔记】30-34_栈的定义_栈的分类_栈程序演示_栈的日常具体应用
- 复杂网络入门读物
- Linux--Advance getenv的非可重入版本
- SOA webservice
- NY2 括号匹配问题
- 0018.scala文件的读取写入操作代码
- Android按钮单击事件的四种常用写法总结