UserDefault 用户首选项读写 swift

//

// ViewController.swift

// 首选项数据读写

//

// Created by mac on 15/7/12.

// Copyright (c) 2015年 fangyuhao. All rights reserved.

//

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var btnSave: UIButton!
@IBOutlet weak var inputText: UITextView!
@IBOutlet weak var outputText: UITextView!
var ud:NSUserDefaults!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
ud = NSUserDefaults.standardUserDefaults()
if let value:AnyObject = ud.objectForKey("data"){
outputText.text = value as! String
}else{
outputText.text = "No value"
}
} override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
} @IBAction func btnSaveClicked(sender: AnyObject) {
ud.setObject(inputText.text, forKey: "data")
println("saved")
}

}

上一篇:【PYTHON】二维码生成


下一篇:生成mif文件的几种方法总结