質問編集履歴
4
タイトルを変更しました、
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
録音の承認を確認してリクエストする
|
test
CHANGED
File without changes
|
3
swiftUIでした。
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
2
具体的にしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,30 +32,502 @@
|
|
32
32
|
|
33
33
|
|
34
34
|
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
下記のコードにボイスメモを入れたいと思っています。
|
40
|
+
|
41
|
+
今はまだ、入れてません。
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
![イメージ説明](1efd51ab17a5809bee36787352f150b4.png)
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
![イメージ説明](8bb74f15ac9ed0ea31f9c65765b5507d.png)
|
54
|
+
|
55
|
+
|
56
|
+
|
35
|
-
###
|
57
|
+
### 該当のソースコード
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
```newTask
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
//
|
66
|
+
|
67
|
+
// newTask.swift
|
68
|
+
|
69
|
+
// voiceAPP
|
70
|
+
|
71
|
+
//
|
72
|
+
|
73
|
+
// Created by user on 2020/09/06.
|
74
|
+
|
75
|
+
// Copyright © 2020 user. All rights reserved.
|
76
|
+
|
77
|
+
//
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
import SwiftUI
|
82
|
+
|
83
|
+
import AVFoundation
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
struct newTask: View {
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
@State var task: String = ""
|
104
|
+
|
105
|
+
@State var task2: String = ""
|
106
|
+
|
107
|
+
@State var time: Date? = Date()
|
108
|
+
|
109
|
+
@State var category: Int16 = Entity.Category.ImpUrg_1st.rawValue
|
110
|
+
|
111
|
+
var categories: [Entity.Category]
|
112
|
+
|
113
|
+
= [.ImpUrg_1st, .ImpNUrg_2nd, .NImpUrg_3rd, .NImpNUrg_4th, .NImpNUrg_5th, .NImpNUrg_6th]
|
114
|
+
|
115
|
+
@Environment(.managedObjectContext) var viewContext
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
fileprivate func save() {
|
120
|
+
|
121
|
+
do {
|
122
|
+
|
123
|
+
try self.viewContext.save()
|
124
|
+
|
125
|
+
} catch {
|
126
|
+
|
127
|
+
let nserror = error as NSError
|
128
|
+
|
129
|
+
fatalError("Unresolved error (nserror), (nserror.userInfo)")
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
//enviromentは、
|
138
|
+
|
139
|
+
@Environment(.presentationMode) var presentationMode
|
140
|
+
|
141
|
+
var body: some View {
|
142
|
+
|
143
|
+
NavigationView {
|
144
|
+
|
145
|
+
Form {
|
146
|
+
|
147
|
+
Section(header: Text("タスク")) {
|
148
|
+
|
149
|
+
TextField("情報の入力", text: $task)}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
Section(header: Toggle(isOn: Binding(isNotNil: $time, defaultValue: Date())){Text("時間設定")}) {
|
162
|
+
|
163
|
+
if time != nil {
|
164
|
+
|
165
|
+
DatePicker(selection: Binding($time, Date()), label: { Text("日時")})
|
166
|
+
|
167
|
+
} else {
|
168
|
+
|
169
|
+
Text("時間未設定").foregroundColor(.secondary)}}
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
Picker(selection: $category, label: Text("種類")) {
|
180
|
+
|
181
|
+
ForEach(categories, id: .self) { category in
|
182
|
+
|
183
|
+
HStack {
|
184
|
+
|
185
|
+
CategoryImage(category)
|
186
|
+
|
187
|
+
Text(category.toString())
|
188
|
+
|
189
|
+
}.tag(category.rawValue)}}
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
Section(header: Text("操作")) {
|
200
|
+
|
201
|
+
Button(action: {
|
202
|
+
|
203
|
+
self.presentationMode.wrappedValue.dismiss()
|
204
|
+
|
205
|
+
}) {
|
206
|
+
|
207
|
+
HStack(alignment: .center) {
|
208
|
+
|
209
|
+
Image(systemName: "minus.circle.fill")
|
210
|
+
|
211
|
+
Text("キャンセル")
|
212
|
+
|
213
|
+
}.foregroundColor(.red)}}
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
Section(header: Text("メモ")) {
|
224
|
+
|
225
|
+
TextField("メモ", text: $task2)}
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
}.navigationBarTitle("内容の追加")
|
234
|
+
|
235
|
+
.navigationBarItems(trailing: Button(action: {
|
236
|
+
|
237
|
+
Entity.create(in: self.viewContext, category: Entity.Category(rawValue: self.category) ?? .ImpUrg_1st,
|
238
|
+
|
239
|
+
task: self.task, time: self.time) //task2: self.task
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
self.save()
|
252
|
+
|
253
|
+
//dismissで画面を閉じる
|
254
|
+
|
255
|
+
self.presentationMode.wrappedValue.dismiss()
|
256
|
+
|
257
|
+
}) {
|
258
|
+
|
259
|
+
Text("保存")
|
260
|
+
|
261
|
+
})
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
struct newTask_Previews: PreviewProvider {
|
272
|
+
|
273
|
+
static let context = (UIApplication.shared.delegate as! AppDelegate)
|
274
|
+
|
275
|
+
.persistentContainer.viewContext
|
276
|
+
|
277
|
+
static var previews: some View {
|
278
|
+
|
279
|
+
newTask()
|
280
|
+
|
281
|
+
.environment(.managedObjectContext, context)
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
}
|
286
|
+
|
287
|
+
|
36
288
|
|
37
289
|
|
38
290
|
|
39
291
|
```
|
40
292
|
|
293
|
+
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
### 該当のソースコード
|
300
|
+
|
301
|
+
```EditTask
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
//
|
306
|
+
|
307
|
+
// EditTask.swift
|
308
|
+
|
309
|
+
// voiceAPP
|
310
|
+
|
311
|
+
//
|
312
|
+
|
313
|
+
// Created by user on 2020/09/07.
|
314
|
+
|
315
|
+
// Copyright © 2020 user. All rights reserved.
|
316
|
+
|
317
|
+
//
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
import SwiftUI
|
322
|
+
|
323
|
+
import AVFoundation
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
struct EditTask: View {
|
330
|
+
|
331
|
+
@ObservedObject var todo: Entity
|
332
|
+
|
333
|
+
@State var showingSheet = false
|
334
|
+
|
335
|
+
var categories: [Entity.Category]
|
336
|
+
|
337
|
+
= [.ImpUrg_1st, .ImpNUrg_2nd, .NImpUrg_3rd, .NImpNUrg_4th, .NImpNUrg_5th, .NImpNUrg_6th]
|
338
|
+
|
339
|
+
@Environment(.managedObjectContext) var viewContext
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
fileprivate func save() {
|
344
|
+
|
345
|
+
do {
|
346
|
+
|
347
|
+
try self.viewContext.save()
|
348
|
+
|
349
|
+
} catch {
|
350
|
+
|
351
|
+
let nserror = error as NSError
|
352
|
+
|
353
|
+
fatalError("Unresolved error (nserror), (nserror.userInfo)")
|
354
|
+
|
355
|
+
}
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
fileprivate func delete() {
|
362
|
+
|
363
|
+
viewContext.delete(todo)
|
364
|
+
|
365
|
+
save()
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
//enviromentは、
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
@Environment(.presentationMode) var presentationMode
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
var body: some View {
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
Form {
|
384
|
+
|
385
|
+
Section(header: Text("タスク")) {
|
386
|
+
|
387
|
+
TextField("情報の入力", text: Binding($todo.task,"内容の編集"))
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
}
|
394
|
+
|
395
|
+
Section(header: Toggle(isOn: Binding(isNotNil: $todo.time, defaultValue: Date())){Text("時間設定")}) {
|
396
|
+
|
397
|
+
if todo.time != nil {
|
398
|
+
|
399
|
+
DatePicker(selection: Binding($todo.time, Date()), label: { Text("日時")})
|
400
|
+
|
41
|
-
|
401
|
+
} else {
|
402
|
+
|
403
|
+
Text("時間未設定").foregroundColor(.secondary)
|
404
|
+
|
405
|
+
}
|
406
|
+
|
407
|
+
}
|
408
|
+
|
409
|
+
Picker(selection: $todo.category, label: Text("種類")) {
|
410
|
+
|
411
|
+
ForEach(categories, id: .self) { category in
|
412
|
+
|
413
|
+
HStack {
|
414
|
+
|
415
|
+
CategoryImage(category)
|
416
|
+
|
417
|
+
Text(category.toString())
|
418
|
+
|
419
|
+
}.tag(category.rawValue)
|
420
|
+
|
421
|
+
}
|
422
|
+
|
423
|
+
}
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
Section(header: Text("メモ")) {
|
428
|
+
|
429
|
+
TextField("メモ", text: Binding($todo.task2,"メモ"))
|
430
|
+
|
431
|
+
}
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
Section(header: Text("操作")) {
|
438
|
+
|
439
|
+
Button(action: {
|
440
|
+
|
441
|
+
self.showingSheet = true
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
}) {
|
446
|
+
|
447
|
+
HStack(alignment: .center) {
|
448
|
+
|
449
|
+
Image(systemName: "minus.circle.fill")
|
450
|
+
|
451
|
+
Text("削除")
|
452
|
+
|
453
|
+
}.foregroundColor(.red)}}
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
}.navigationBarTitle("内容の編集")
|
466
|
+
|
467
|
+
.navigationBarItems(trailing: Button(action: {
|
468
|
+
|
469
|
+
self.save()
|
470
|
+
|
471
|
+
//dismissで画面を閉じる
|
472
|
+
|
473
|
+
self.presentationMode.wrappedValue.dismiss()
|
474
|
+
|
475
|
+
}) {
|
476
|
+
|
477
|
+
Text("閉じる")
|
478
|
+
|
479
|
+
})
|
480
|
+
|
481
|
+
.actionSheet(isPresented: $showingSheet) {
|
482
|
+
|
483
|
+
ActionSheet(title: Text("タスクの削除"), message: Text("情報を削除します。よろしいですか?"), buttons: [.destructive(Text("削除")) {
|
484
|
+
|
485
|
+
self.delete()
|
486
|
+
|
487
|
+
self.presentationMode.wrappedValue.dismiss()
|
488
|
+
|
489
|
+
},
|
490
|
+
|
491
|
+
.cancel(Text(" キャンセル"))
|
492
|
+
|
493
|
+
])
|
494
|
+
|
495
|
+
}
|
496
|
+
|
497
|
+
}
|
498
|
+
|
499
|
+
}
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
struct EditTask_Previews: PreviewProvider {
|
504
|
+
|
505
|
+
static let context = (UIApplication.shared.delegate as! AppDelegate)
|
506
|
+
|
507
|
+
.persistentContainer.viewContext
|
508
|
+
|
509
|
+
static var previews: some View {
|
510
|
+
|
511
|
+
let newTodo = Entity(context: context)
|
512
|
+
|
513
|
+
return NavigationView {
|
514
|
+
|
515
|
+
EditTask(todo: newTodo)
|
516
|
+
|
517
|
+
.environment(.managedObjectContext, context)
|
518
|
+
|
519
|
+
}
|
520
|
+
|
521
|
+
}
|
522
|
+
|
523
|
+
}
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
|
42
528
|
|
43
529
|
```
|
44
530
|
|
45
|
-
|
46
|
-
|
47
|
-
### 該当のソースコード
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
```ここに言語名を入力
|
52
|
-
|
53
|
-
ソースコード
|
54
|
-
|
55
|
-
```
|
56
|
-
|
57
|
-
|
58
|
-
|
59
531
|
### 試したこと
|
60
532
|
|
61
533
|
|
1
上の説明のことです。
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,11 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
-
|
17
|
+
上の文章がよくわかりません。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
18
22
|
|
19
23
|
初めのアプリのinfo.plistの説明は、写真がついていたので、どこに設定すればいいかを把握できました。
|
20
24
|
|