Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

参考にしたサイト: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
    }
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away