1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

辞書をを保存して、読み込む

Last updated at Posted at 2015-11-08

参考にしたサイト:http://swift-salaryman.com/nsuserdefaults.php

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        //データの設定
        saveData("hege", kana:"tage", title:"tegetege", filename: "ahsuet")
        //読み込み
        let arr: AnyObject! = NSUserDefaults.standardUserDefaults().dictionaryForKey("hogeDic");
        print(arr);
        /* {
        title = "swift-salaryman";
        url = "http://swift-salaryman.com/";
        */
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func saveData(name:String, kana:String, title:String, filename:String) -> Dictionary<String, AnyObject>{
        //保存
        let info:[String] = [kana, title, filename]
        let hogeDic: Dictionary = [name:info]
        NSUserDefaults.standardUserDefaults().setObject(hogeDic, forKey:"hogeDic");
        NSUserDefaults.standardUserDefaults().synchronize();
        
        return hogeDic
    }
}
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?