Swift fixing array for notifications -


i'm trying fix notifications displaying every day should pack school next day.

everything seems ok, content.subtitle shows error :

thread 1: exc_breakpoint (code=1, subcode=0x1007dbb00)

is there problem array also? searched answer, looks nobody used array notification body. possible? , if it's not can replace better replacement? help.

let plan = [     ["dzien": "sunday", "lekcje": nil],     ["dzien": "saturday", "lekcje":["pon1","pon2","pon3"]],     ["dzien": "tuesday", "lekcje":["wt1","wt2","wt3"]],     ["dzien": "wednesday", "lekcje":["sr1","sr2","sr3"]],     ["dzien": "thursday", "lekcje":["cz1","cz2","cz3"]],     ["dzien": "friday", "lekcje":["pt1","pt2","pt3"]],     ["dzien": "saturday", "lekcje": nil], ]  func getdayofweek() -> int {     let mycalendar = calendar(identifier: .gregorian)     let weekday = mycalendar.component(.weekday, from: date())     return weekday - 1 }      @objc func registerlocal() {     let center = unusernotificationcenter.current()      center.requestauthorization(options: [.alert, .badge, .sound]) { (granted, error) in         if granted {             print("sukces")         } else {             print("nie dzieƂa")         }     } }      @objc func schedulelocal() {         let center = unusernotificationcenter.current()          let content = unmutablenotificationcontent()          let d = getdayofweek()%6         let dzis = plan[d]         if dzis["lekcje"] != nil {          content.title = "pack up"         content.subtitle = dzis["dzien"]         var lekcje = ""         lekcja in dzis["lekcje"] {             lekcje+="\(lekcja)\n"         }         content.body = lekcje         content.userinfo = ["customdata": "fizzbuzz"]         } else {          content.title = "tommorow \(dzis["dzien"]), don't have subjects."         }          var datecomponents = datecomponents()         datecomponents.hour = 16         datecomponents.minute = 00         let trigger = uncalendarnotificationtrigger(datematching: datecomponents, repeats: true)          let request = unnotificationrequest(identifier: uuid().uuidstring, content: content, trigger: trigger)         center.add(request)              } } 

the problem compiler infers type of plans [string:any] , when trying content.subtitle = dzis["dzien"], dzis["dzien"] of type any , not string.

you have cast string in order work.

guard let subtitle = dzis["dzien"] as? string else {return} content.subtitle = subtitle 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -