質問編集履歴

2

編集

2018/10/13 11:25

投稿

mogiruri
mogiruri

スコア37

test CHANGED
File without changes
test CHANGED
@@ -344,96 +344,32 @@
344
344
 
345
345
  ```
346
346
 
347
-
347
+ .
348
+
349
+ .
350
+
351
+ #アイデア?
352
+
353
+ ランダムに要素を取得する randItem がグローバルなので notificationContent の forKey に変数をこのまま与えてしまうと、グローバルで作成されたランダム数がずっと入り続けてしまうのが原因なのはわかりました。
354
+
355
+ なので、cellの情報が詰まったlistをプッシュのディスプレイ用に複製(var notiList = list)して、
356
+
357
+ 以下のようなのを用いて使ったら削除して、別のを取得してそれを代入し直し、というプロセスとどこかに入れたらいいのでは?と思いついたのですが、、、
358
+
359
+ この func sendLocalPushは一度呼ばれるだけなので、ここで毎回発火させるのは難しい。。。?
348
360
 
349
361
  ```swift
350
362
 
351
- import Foundation
352
-
353
- import UIKit
354
-
355
-
356
-
357
-
358
-
359
- class AddViewController: UIViewController{
360
-
361
-
362
-
363
- // Outlets
364
-
365
- @IBOutlet weak var wordInput: UITextField!
366
-
367
- @IBOutlet weak var meaningInput: UITextField!
368
-
369
-
370
-
371
- var listItem = ""
372
-
373
-
374
-
375
-
376
-
377
- @IBAction func addItem(_ sender: Any) {
378
-
379
-
380
-
381
- if wordInput.text != "" && meaningInput.text != "" {
382
-
383
- listItem = "(wordInput.text!) : (meaningInput.text!)"
384
-
385
- list.append(listItem)
363
+ notiList.remove(at: randomItem)
386
-
387
- wordInput.text = ""
364
+
388
-
389
- meaningInput.text = ""
365
+ randomItem = Int(arc4random_uniform(UInt32(notiList.count)))
390
-
391
-
392
-
366
+
367
+
368
+
393
- }
369
+ content.body = NSString.localizedUserNotificationString(forKey: notiList[randomItem], arguments: nil)
394
-
395
-
396
-
397
- }
398
-
399
-
400
-
401
-
402
-
403
-
404
-
405
-
406
-
407
- }
408
370
 
409
371
  ```
410
372
 
411
- .
412
-
413
- .
414
-
415
- #アイデア?
416
-
417
- ランダムに要素を取得する randItem がグローバルなので notificationContent の forKey に変数をこのまま与えてしまうと、グローバルで作成されたランダム数がずっと入り続けてしまうのが原因なのはわかりました。
418
-
419
- なので、cellの情報が詰まったlistをプッシュのディスプレイ用に複製(var notiList = list)して、
420
-
421
- 以下のようなのを用いて使ったら削除して、別のを取得してそれを代入し直し、というプロセスとどこかに入れたらいいのでは?と思いついたのですが、、、
422
-
423
- この func sendLocalPushは一度呼ばれるだけなので、ここで毎回発火させるのは難しい。。。?
424
-
425
- ```swift
426
-
427
- notiList.remove(at: randomItem)
428
-
429
- randomItem = Int(arc4random_uniform(UInt32(notiList.count)))
430
-
431
-
432
-
433
- content.body = NSString.localizedUserNotificationString(forKey: notiList[randomItem], arguments: nil)
434
-
435
- ```
436
-
437
373
 
438
374
 
439
375
  ほかに何か解決策があればよろしくお願いいたします。

1

コード追加

2018/10/13 11:25

投稿

mogiruri
mogiruri

スコア37

test CHANGED
File without changes
test CHANGED
@@ -344,6 +344,70 @@
344
344
 
345
345
  ```
346
346
 
347
+
348
+
349
+ ```swift
350
+
351
+ import Foundation
352
+
353
+ import UIKit
354
+
355
+
356
+
357
+
358
+
359
+ class AddViewController: UIViewController{
360
+
361
+
362
+
363
+ // Outlets
364
+
365
+ @IBOutlet weak var wordInput: UITextField!
366
+
367
+ @IBOutlet weak var meaningInput: UITextField!
368
+
369
+
370
+
371
+ var listItem = ""
372
+
373
+
374
+
375
+
376
+
377
+ @IBAction func addItem(_ sender: Any) {
378
+
379
+
380
+
381
+ if wordInput.text != "" && meaningInput.text != "" {
382
+
383
+ listItem = "(wordInput.text!) : (meaningInput.text!)"
384
+
385
+ list.append(listItem)
386
+
387
+ wordInput.text = ""
388
+
389
+ meaningInput.text = ""
390
+
391
+
392
+
393
+ }
394
+
395
+
396
+
397
+ }
398
+
399
+
400
+
401
+
402
+
403
+
404
+
405
+
406
+
407
+ }
408
+
409
+ ```
410
+
347
411
  .
348
412
 
349
413
  .