質問するログイン新規登録

回答編集履歴

4

再修正

2015/12/08 20:33

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -1,15 +1,60 @@
1
- 勘違いしていたので修正しました。
1
+ 再度修正しました。
2
- 多分れで良いかと、、、
2
+ ちら環境はXcode7.1です。
3
3
 
4
+ 齟齬が無い様にswiftコードとplist(XML)のコードを載せておきます。
5
+
6
+ これで以下の様に出力されました。
7
+ Answer = 答え
8
+ Dog = 犬
9
+ And = 同じ
10
+
4
11
  ```swift
5
- if let dict = dictionary.objectForKey("Word") {
12
+ import UIKit
6
-
13
+
7
- let Adict = dict as! NSMutableDictionary
14
+ class ViewController: UIViewController {
8
-
15
+
9
- if let answearDict = Adict.objectForKey("A") {
16
+ override func viewDidLoad() {
17
+ super.viewDidLoad()
10
18
 
19
+ let path = NSBundle.mainBundle().pathForResource("English", ofType: "plist")
20
+ let dictionary: NSDictionary = NSDictionary(contentsOfFile: path!)!
21
+
22
+
23
+ if let wordDict = dictionary["Word"] {
24
+ if let Adict = wordDict["A"] {
25
+ for (Eng, Jap) in Adict as! Dictionary<String, String> {
11
- print("Dog = \(answearDict["Dog"] as! String)")
26
+ print("\(Eng)" + " = " + "\(Jap)")
12
- //=> Dog = 犬
27
+ }
28
+ }
29
+ }
13
30
  }
31
+
32
+ override func didReceiveMemoryWarning() {
33
+ super.didReceiveMemoryWarning()
34
+ }
14
35
  }
36
+
37
+ ```
38
+
39
+
40
+ ```xml
41
+ <?xml version="1.0" encoding="UTF-8"?>
42
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
43
+ <plist version="1.0">
44
+ <dict>
45
+ <key>Word</key>
46
+ <dict>
47
+ <key>A</key>
48
+ <dict>
49
+ <key>Dog</key>
50
+ <string>犬</string>
51
+ <key>And</key>
52
+ <string>同じ</string>
53
+ <key>Answer</key>
54
+ <string>答え</string>
55
+ </dict>
56
+ </dict>
57
+ </dict>
58
+ </plist>
59
+
15
60
  ```

3

修正

2015/12/08 20:33

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -1,20 +1,14 @@
1
- > Dog string  犬
1
+ 勘違いしていたので修正しました。
2
- > という風に書いていて「Dog = 犬」と、取り出したいのすがplistではできなでしょう
2
+ 多分これと、、、
3
3
 
4
- ちょっとこの部分が理解できないのですが、、、すみません。
5
- 値は以下の様にしてとりだせます。
6
-
7
- 多分イメージと違うかもしれないので、分からなかったら聞いてください。
8
-
9
4
  ```swift
10
-
11
5
  if let dict = dictionary.objectForKey("Word") {
12
6
 
13
7
  let Adict = dict as! NSMutableDictionary
14
8
 
15
9
  if let answearDict = Adict.objectForKey("A") {
16
10
 
17
- print("\(answearDict["Key"] as! String)" + " = " + "\(answearDict["value"] as! String)")
11
+ print("Dog = \(answearDict["Dog"] as! String)")
18
12
  //=> Dog = 犬
19
13
  }
20
14
  }

2

回答変更

2015/12/08 14:56

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -1,10 +1,21 @@
1
+ > Dog string  犬
1
- Plistの定義はこちらではこのように実行ましたが同じ様にってますか?
2
+ > とい書いいて「Dog = 犬」と、取り出したいのですplistではできないでしょうか?
2
3
 
3
- ![イメージ説明](126203a59fe2cf45a46742de8aea45e2.png)
4
+ ちょっとこの部分が理解できないのですが、、、すみません。
4
-
5
+ 値は以下の様にしてとりだせます。
5
-
6
6
 
7
- ちなみに直は以下の箇所のみ
7
+ 多分イメージと違うかもれないので、分からなかったら聞いてください
8
+
8
9
  ```swift
10
+
9
- print("\(value["value"] as! String)")
11
+ if let dict = dictionary.objectForKey("Word") {
12
+
13
+ let Adict = dict as! NSMutableDictionary
14
+
15
+ if let answearDict = Adict.objectForKey("A") {
16
+
17
+ print("\(answearDict["Key"] as! String)" + " = " + "\(answearDict["value"] as! String)")
18
+ //=> Dog = 犬
19
+ }
20
+ }
10
21
  ```

1

説明追記

2015/12/08 14:51

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -1,3 +1,10 @@
1
1
  Plistの定義はこちらではこのようにして実行しましたが同じ様になっていますか?
2
2
 
3
- ![イメージ説明](126203a59fe2cf45a46742de8aea45e2.png)
3
+ ![イメージ説明](126203a59fe2cf45a46742de8aea45e2.png)
4
+
5
+
6
+
7
+ ちなみに直したのは以下の箇所のみです。
8
+ ```swift
9
+ print("\(value["value"] as! String)")
10
+ ```