質問編集履歴
3
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,7 +34,7 @@
|
|
34
34
|
|
35
35
|
let cell = tableView.dequeueReusableCell(withIdentifier: "EditTableViewCell", for: indexPath) as! EditTableViewCell
|
36
36
|
|
37
|
-
self.List = getValue()
|
37
|
+
// self.List = getValue()
|
38
38
|
|
39
39
|
cell.idLabel.text = "\(indexPath.row + 1)"
|
40
40
|
cell.titleLabel.text = List[indexPath.row].name
|
@@ -68,6 +68,7 @@
|
|
68
68
|
let encoder = JSONEncoder()
|
69
69
|
if let encodedValue = try? encoder.encode(self.List) {
|
70
70
|
UserDefaults.standard.set(encodedValue, forKey: "List")
|
71
|
+
self.save()
|
71
72
|
print("削除なう")
|
72
73
|
print(self.List.count)
|
73
74
|
}
|
@@ -91,6 +92,21 @@
|
|
91
92
|
}
|
92
93
|
}
|
93
94
|
|
95
|
+
private func save() {
|
96
|
+
guard let data = encoded() else { return }
|
97
|
+
UserDefaults.standard.setValue(data, forKey: "TwitterUserList")
|
98
|
+
print("保存完了しました")
|
99
|
+
}
|
100
|
+
|
101
|
+
private func encoded() -> Data? {
|
102
|
+
do {
|
103
|
+
let encoder = JSONEncoder()
|
104
|
+
let data = try encoder.encode(self.userList)
|
105
|
+
return data
|
106
|
+
} catch {
|
107
|
+
return nil
|
108
|
+
}
|
109
|
+
}
|
94
110
|
|
95
111
|
```
|
96
112
|
|
2
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -37,10 +37,10 @@
|
|
37
37
|
self.List = getValue()
|
38
38
|
|
39
39
|
cell.idLabel.text = "\(indexPath.row + 1)"
|
40
|
-
cell.titleLabel.text =
|
40
|
+
cell.titleLabel.text = List[indexPath.row].name
|
41
|
-
cell.name.text =
|
41
|
+
cell.name.text = List[indexPath.row].url
|
42
42
|
|
43
|
-
let urlString =
|
43
|
+
let urlString = List[indexPath.row].profile_image_url
|
44
44
|
Nuke.loadImage(with: URL(string: urlString)!, into: cell.userImage)
|
45
45
|
|
46
46
|
return cell
|
@@ -62,11 +62,11 @@
|
|
62
62
|
// セルの削除
|
63
63
|
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
|
64
64
|
|
65
|
-
|
65
|
+
List.remove(at: indexPath.row)
|
66
66
|
tableView.deleteRows(at: [indexPath as IndexPath], with: UITableView.RowAnimation.automatic)
|
67
67
|
// 追加:削除した内容を保存
|
68
68
|
let encoder = JSONEncoder()
|
69
|
-
if let encodedValue = try? encoder.encode(self.
|
69
|
+
if let encodedValue = try? encoder.encode(self.List) {
|
70
70
|
UserDefaults.standard.set(encodedValue, forKey: "List")
|
71
71
|
print("削除なう")
|
72
72
|
print(self.List.count)
|
@@ -91,6 +91,7 @@
|
|
91
91
|
}
|
92
92
|
}
|
93
93
|
|
94
|
+
|
94
95
|
```
|
95
96
|
|
96
97
|
### 試したこと
|
1
タイトル修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
構造体を削除したい
|
1
|
+
Swiftの構造体から特定の行を削除したい
|
test
CHANGED
File without changes
|