質問編集履歴
2
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -44,8 +44,8 @@
|
|
44
44
|
|
45
45
|
required init?(coder aDecoder: NSCoder) {
|
46
46
|
todo = aDecoder.decodeObject(forKey: "todo") as! String
|
47
|
-
|
47
|
+
time1 = aDecoder.decodeInteger(forKey: "time1")
|
48
|
-
|
48
|
+
time2 = aDecoder.decodeInteger(forKey: "time2")
|
49
49
|
date = aDecoder.decodeObject(forKey: "date") as! Date
|
50
50
|
}
|
51
51
|
}
|
1
変数の更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,8 +12,8 @@
|
|
12
12
|
受け渡したいデータは、以下の4つで、これらを格納するカスタムクラスをUserDefaultsで取り扱いたいです。
|
13
13
|
|
14
14
|
1.todo : String
|
15
|
-
2.
|
15
|
+
2.time1 : Int
|
16
|
-
3.
|
16
|
+
3.time2 : Int
|
17
17
|
4.date : Date
|
18
18
|
|
19
19
|
### 該当のソースコード
|
@@ -24,28 +24,28 @@
|
|
24
24
|
class Content:NSObject, NSCoding {
|
25
25
|
|
26
26
|
let todo: String
|
27
|
-
let
|
27
|
+
let time1: Int
|
28
|
-
let
|
28
|
+
let time2: Int
|
29
29
|
let date: Date
|
30
30
|
|
31
|
-
init(todo:String,
|
31
|
+
init(todo:String, time1:Int, time2:Int, date:Date) {
|
32
32
|
self.todo = todo
|
33
|
-
self.
|
33
|
+
self.time1 = time1
|
34
|
-
self.
|
34
|
+
self.time2 = time2
|
35
35
|
self.date = date
|
36
36
|
}
|
37
37
|
|
38
38
|
func encode(with aCoder: NSCoder) {
|
39
39
|
aCoder.encode(self.todo, forKey: "todo")
|
40
|
-
aCoder.encode(self.estimate, forKey: "
|
40
|
+
aCoder.encode(self.estimate, forKey: "time1")
|
41
|
-
aCoder.encode(self.actual, forKey: "
|
41
|
+
aCoder.encode(self.actual, forKey: "time2")
|
42
42
|
aCoder.encode(self.date, forKey: "date")
|
43
43
|
}
|
44
44
|
|
45
45
|
required init?(coder aDecoder: NSCoder) {
|
46
46
|
todo = aDecoder.decodeObject(forKey: "todo") as! String
|
47
|
-
estimate = aDecoder.decodeInteger(forKey: "
|
47
|
+
estimate = aDecoder.decodeInteger(forKey: "time1")
|
48
|
-
actual = aDecoder.decodeInteger(forKey: "
|
48
|
+
actual = aDecoder.decodeInteger(forKey: "time2")
|
49
49
|
date = aDecoder.decodeObject(forKey: "date") as! Date
|
50
50
|
}
|
51
51
|
}
|
@@ -69,13 +69,13 @@
|
|
69
69
|
timer.invalidate()
|
70
70
|
|
71
71
|
let todoString:String = todo.text!
|
72
|
-
var
|
72
|
+
var time1Int:Int = Int()
|
73
|
-
var
|
73
|
+
var time2Int:Int = Int()
|
74
74
|
let now:Date = Date()
|
75
75
|
|
76
|
-
let index = timePickerOption.firstIndex(of:
|
76
|
+
let index = timePickerOption.firstIndex(of: timeLabel.text!)
|
77
|
-
|
77
|
+
time1Int = convertedTimePickerOption[index!]
|
78
|
-
|
78
|
+
time2Int = time1Int - count
|
79
79
|
|
80
80
|
// done!押下時の時間を"yyyy/mm/dd"に変換する
|
81
81
|
let f = DateFormatter()
|
@@ -86,7 +86,7 @@
|
|
86
86
|
let s = f.string(from: now)
|
87
87
|
|
88
88
|
// contentに書き込み、contentsにappend
|
89
|
-
content = [Content(todo: todoString,
|
89
|
+
content = [Content(todo: todoString, time1: time1Int, time2: time2Int, date: f.date(from: s)!)]
|
90
90
|
contents.append(content)
|
91
91
|
|
92
92
|
// UserDefaultsに保存
|