Plist文件的操作
来源:互联网 发布:软件授权使用协议书 编辑:程序博客网 时间:2024/05/16 14:23
plist文件是苹果自带的配置文件 主要是以xml的格式进行匹配的
创建的时候 选择resource的plist来进行创建 他主要有两种类型 一种是字典类型的 还有一种是数组类型的
可以通过添加子元素来进行创建
通过数组来解析plist文件 将plist文件解析后,保存在一个数组中,随后将其输出即可 此时的plist文件一定要是数组类型的 否则无法输出
import UIKitclass 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 UIKitclass 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. }}
0 0
- Plist文件的操作
- Plist文件的操作
- .plist文件的读写操作
- Plist文件的读写操作
- plist 文件的读写操作
- Plist文件的读写操作
- 对plist文件的读写操作
- iphone info.plist文件的操作。
- IOS plist文件的增删操作
- Info.plist文件的一些操作
- plist文件的存取或读写操作
- IOS学习之plist文件的操作
- cocos lua 对plist文件的操作
- 数据持久化-plist文件的操作
- iOS plist文件的读写删操作
- plist文件操作总结
- plist文件读写操作
- plist文件操作
- JavaWeb之-------------网页中的Cookie技术
- myEclipse中配置maven
- App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure.
- 九度oj-合并两个排序的链表
- 初入iOS自学问题笔记
- Plist文件的操作
- sql无法启动MSSQLSERVER,报错17051
- 图——操作用邻接表存储的图
- linux下配置Qt5 开发环境
- 网站大并发处理
- 图片预览所遇到的获取图片尺寸问题
- HDU 1027 STL
- hdu 4578 Transformation 线段树
- 【教程】爱玩吧QQ空间说说刷赞网怎么刷秒赞教程