質問編集履歴
3
関連コードの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -164,8 +164,108 @@
|
|
164
164
|
|
165
165
|
}
|
166
166
|
|
167
|
+
|
168
|
+
|
169
|
+
//データを全件取得する
|
170
|
+
|
171
|
+
static func selectAll() -> [Data] {
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
var data = [Data]()
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "Data")
|
180
|
+
|
181
|
+
do{
|
182
|
+
|
183
|
+
data = try context.fetch(request) as! [Data]
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
return data
|
188
|
+
|
189
|
+
}catch{
|
190
|
+
|
191
|
+
print("エラー")
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
return data
|
196
|
+
|
197
|
+
}
|
198
|
+
|
167
199
|
}
|
168
200
|
|
169
201
|
```
|
170
202
|
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
```SWift
|
210
|
+
|
211
|
+
class AppDelegate: UIResponder, UIApplicationDelegate {
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
//CoreData関連部分のみ抜粋
|
216
|
+
|
217
|
+
lazy var persistentContainer: NSPersistentContainer = {
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
let container = NSPersistentContainer(name: "CoreDataTest")
|
222
|
+
|
223
|
+
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
|
224
|
+
|
225
|
+
if let error = error as NSError? {
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
fatalError("Unresolved error (error), (error.userInfo)")
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
})
|
234
|
+
|
235
|
+
return container
|
236
|
+
|
237
|
+
}()
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
func saveContext () {
|
242
|
+
|
243
|
+
let context = persistentContainer.viewContext
|
244
|
+
|
245
|
+
if context.hasChanges {
|
246
|
+
|
247
|
+
do {
|
248
|
+
|
249
|
+
try context.save()
|
250
|
+
|
251
|
+
} catch {
|
252
|
+
|
253
|
+
let nserror = error as NSError
|
254
|
+
|
255
|
+
fatalError("Unresolved error (nserror), (nserror.userInfo)")
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
```
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
|
171
271
|
![イメージ説明](cb85c03dc996ccaef86c2daafc328090.png)
|
2
ミスを削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
質問
|
1
|
+
質問失礼します。
|
2
2
|
|
3
3
|
|
4
4
|
|
1
スクリーンショットを掲載
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
質問
|
1
|
+
質問![イメージ説明](ac2bcebbd6eaa6ea42427baabd855652.png)
|
2
2
|
|
3
3
|
|
4
4
|
|
@@ -167,3 +167,5 @@
|
|
167
167
|
}
|
168
168
|
|
169
169
|
```
|
170
|
+
|
171
|
+
![イメージ説明](cb85c03dc996ccaef86c2daafc328090.png)
|