質問編集履歴

5

解決

2015/08/05 08:06

投稿

Nicola
Nicola

スコア21

test CHANGED
File without changes
test CHANGED
@@ -63,3 +63,99 @@
63
63
  正しい開き方を教えていただけないでしょうか。
64
64
 
65
65
  よろしくお願いします。
66
+
67
+
68
+
69
+
70
+
71
+ 解決しました。
72
+
73
+
74
+
75
+ 下記のコードが最終コードとなります。
76
+
77
+
78
+
79
+ import Cocoa
80
+
81
+ import Foundation
82
+
83
+ extension String : CollectionType {}
84
+
85
+
86
+
87
+
88
+
89
+ class ViewController: NSViewController {
90
+
91
+
92
+
93
+ override func viewDidLoad() {
94
+
95
+ super.viewDidLoad()
96
+
97
+
98
+
99
+ let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
100
+
101
+ let filePath = paths[0].stringByAppendingPathComponent("test01.txt")
102
+
103
+ print (filePath)
104
+
105
+ let data = htmlStringWithFilePath(filePath)
106
+
107
+
108
+
109
+ data!.enumerateLines { (line, stop) -> () in
110
+
111
+ print(line)
112
+
113
+ print(split(line){ $0 == "\t"})
114
+
115
+ }
116
+
117
+
118
+
119
+ // Do any additional setup after loading the view.
120
+
121
+ }
122
+
123
+
124
+
125
+ override var representedObject: AnyObject? {
126
+
127
+ didSet {
128
+
129
+ // Update the view, if already loaded.
130
+
131
+ }
132
+
133
+ }
134
+
135
+
136
+
137
+ private func htmlStringWithFilePath(path: String) -> String? {
138
+
139
+
140
+
141
+ do {
142
+
143
+ let data = try String(contentsOfFile: path, encoding: NSUTF8StringEncoding)
144
+
145
+ return data
146
+
147
+
148
+
149
+ } catch {
150
+
151
+ print("Lookup error: no HTML file found for path, \(path)")
152
+
153
+ return nil
154
+
155
+ }
156
+
157
+ }
158
+
159
+
160
+
161
+ }

4

syuusei

2015/08/05 08:06

投稿

Nicola
Nicola

スコア21

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
- 以下のコードでpaths[0]認識されないようでエラーになります。
1
+ 以下のコードでlet data = NSString(contentsOfFile: filePath, encoding: NSUTF8StringEncoding, error: nil)がエラーになります。
2
2
 
3
- ViewController.Type dose not have a member named paths というエラーです。
3
+
4
4
 
5
5
 
6
6
 
@@ -20,6 +20,22 @@
20
20
 
21
21
 
22
22
 
23
+ let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
24
+
25
+ let filePath = paths[0].stringByAppendingPathComponent("dictionary00.txt")
26
+
27
+ let data = NSString(contentsOfFile: filePath, encoding: NSUTF8StringEncoding, error: nil)
28
+
29
+ data.enumerateLines { (line, stop) -> () in
30
+
31
+ println(line)
32
+
33
+ println(split(line,{ $0 == "\t"}))
34
+
35
+
36
+
37
+ }
38
+
23
39
  // Do any additional setup after loading the view.
24
40
 
25
41
  }
@@ -38,22 +54,6 @@
38
54
 
39
55
 
40
56
 
41
- let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
42
-
43
- let filePath = paths[0].stringByAppendingPathComponent("dictionary00.txt")
44
-
45
- let data = NSString(contentsOfFile: filePath, encoding: NSUTF8StringEncoding, error: nil)
46
-
47
- data.enumerateLines { (line, stop) -> () in
48
-
49
- println(line)
50
-
51
- println(split(line,{ $0 == "\t"}))
52
-
53
-
54
-
55
- }
56
-
57
57
  }
58
58
 
59
59
 

3

編集

2015/08/02 23:30

投稿

Nicola
Nicola

スコア21

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,12 @@
1
1
  以下のコードでpaths[0]が認識されないようでエラーになります。
2
2
 
3
3
  ViewController.Type dose not have a member named paths というエラーです。
4
+
5
+
6
+
7
+ import Cocoa
8
+
9
+ import Foundation
4
10
 
5
11
 
6
12
 

2

編集

2015/08/01 23:34

投稿

Nicola
Nicola

スコア21

test CHANGED
File without changes
test CHANGED
@@ -1,22 +1,54 @@
1
- 以下のコードで2行目のpaths[0]が認識されないようでエラーになります。
1
+ 以下のコードでpaths[0]が認識されないようでエラーになります。
2
2
 
3
3
  ViewController.Type dose not have a member named paths というエラーです。
4
4
 
5
5
 
6
6
 
7
- let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
7
+ class ViewController: NSViewController {
8
-
9
- let filePath = paths[0].stringByAppendingPathComponent("dictionary00.txt")
10
8
 
11
9
 
12
10
 
13
- let data = NSString(contentsOfFile: filePath, encoding: NSUTF8StringEncoding, error: nil)
11
+ override func viewDidLoad() {
14
12
 
15
- data.enumerateLines { (line, stop) -> () in
13
+ super.viewDidLoad()
16
14
 
17
- println(line)
18
15
 
16
+
17
+ // Do any additional setup after loading the view.
18
+
19
+ }
20
+
21
+
22
+
23
+ override var representedObject: AnyObject? {
24
+
25
+ didSet {
26
+
27
+ // Update the view, if already loaded.
28
+
29
+ }
30
+
31
+ }
32
+
33
+
34
+
35
+ let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
36
+
37
+ let filePath = paths[0].stringByAppendingPathComponent("dictionary00.txt")
38
+
39
+ let data = NSString(contentsOfFile: filePath, encoding: NSUTF8StringEncoding, error: nil)
40
+
41
+ data.enumerateLines { (line, stop) -> () in
42
+
43
+ println(line)
44
+
19
- println(split(line,{ $0 == "\t"}))
45
+ println(split(line,{ $0 == "\t"}))
46
+
47
+
48
+
49
+ }
50
+
51
+ }
20
52
 
21
53
 
22
54
 

1

エラー名追記

2015/08/01 23:33

投稿

Nicola
Nicola

スコア21

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  以下のコードで2行目のpaths[0]が認識されないようでエラーになります。
2
2
 
3
- ViewController.Type dose not have a member named paths
3
+ ViewController.Type dose not have a member named paths というエラーです。
4
4
 
5
5
 
6
6