[IOS] 使用属性列表实现数据持久化
来源:互联网 发布:数据库第六版pdf 编辑:程序博客网 时间:2024/05/21 17:16
//// ViewController.swift// just//// Created by Stary on 4/4/16.// Copyright © 2016 Stary. All rights reserved.//import UIKitclass ViewController: UIViewController { // array of switches @IBOutlet var Switches : [UISwitch]! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let filePath = self.dataFilePath() // judge if the path is available if (NSFileManager.defaultManager().fileExistsAtPath(filePath)) { let array = NSArray(contentsOfFile: filePath) as! [Bool] for var i = 0; i < array.count; i++ { Switches[i].on = array[i] } } let app = UIApplication.sharedApplication() NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationWillResignActive:", name: UIApplicationWillResignActiveNotification, object: app) } // receive the message // Sent when the application is about to move from active to // interruptions (such as an incoming phone call or SMS message) or when the user quits the application // and it begins the transition to the background state. func applicationWillResignActive(notification:NSNotification) { let filePath = self.dataFilePath() let array = (self.Switches as NSArray).valueForKey("on") as! NSArray array.writeToFile(filePath, atomically: true) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } // 寻找文件路径 func dataFilePath() -> String { let paths = NSSearchPathForDirectoriesInDomains( NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true) let documentsDirectory = paths[0] as NSString return documentsDirectory.stringByAppendingPathComponent("data.plist") as String }}
0 0
- [IOS] 使用属性列表实现数据持久化
- IOS 数据持久化之属性列表
- ios学习(五):数据持久化之属性列表(.plist)
- iOS 数据持久化一-属性列表
- iOS 数据持久化一-属性列表 Plist
- iOS数据持久化之属性列表和归档
- iOS数据持久化——属性列表和归档
- 《精通iOS开发·第六版》数据持久化基础知识之属性列表持久化
- iOS持久化存储之属性列表
- 数据持久化-属性列表、归档、NSUserDefaults
- 数据持久化之属性列表
- 数据持久化之属性列表Plist
- IOS 开发学习二十 数据持久化:读写属性列表示例
- IOS数据持久化之一属性列表(或偏好设置)
- IOS开发指南学习——数据持久化(属性列表、对象归档、SQLite)
- ios24-数据的持久化之属性列表
- 数据持久化之归档和属性列表
- 数据持久化之属性列表+对象归档
- monkey调试类命令
- Android之EditText
- Android --- Recyclerview and Cardview
- android问题:getApplicationContext()得到的是什么,一般怎么用?
- thinkphp中模板的if语句多重判断
- [IOS] 使用属性列表实现数据持久化
- Java7新特性一览
- Memcached Client简要介绍
- JavaScriptCore学习之JSPatch源码阅读
- 断点续传学习记录
- 码农小汪-剑指Offer之33 -数组中的逆序对 冒泡排序 归并排序
- 2016年程序员就业形势是什么样的?
- Python 实现Harris 角点检测
- gradle相关