Tuesday, November 21, 2017

How to fix app crash due to Thread 0 error

Leave a Comment

Now I know how to figure out why my app is crashing, could someone help me in fixing this crash please.

enter image description here

Would this do the job ? THank you

 switch tempDayHolder                     {                     case "Monday":                         outputWeekdays.append(2)                     case "Tuesday":                         outputWeekdays.append(3)                     case "Wednesday":                         outputWeekdays.append(4)                     case "Thursday":                         outputWeekdays.append(5)                     case "Friday":                         outputWeekdays.append(6)                     case "Saturday":                         outputWeekdays.append(7)                     case "Sunday":                         outputWeekdays.append(1)                     default :                         outputWeekdays.append(1)                     } 

Apologies if this is a basic question. I am a newbie and learning things from online tutorials and is the first time I've encountered this issue.

Ok so I connected the phone where the crash is happening, went into xcode>Devices and this is the crash log. Any pointers from here would be highly appreciated :

https://pastebin.com/mhTteSBC

1 Answers

Answers 1

(let's ignore your programming style.. as you say you are a newbie)

source misses some types.

So:

1) suppose the complete code is:

import Foundation   var outputWeekdays = [Int]()  class Days {      init() {     }     var daysSelected: String?{         get{             if let returnValue  = UserDefaults.standard.object(forKey: "SELECTED_DAY") as? String{                 return returnValue             }             else{                 return nil             }         }     } } func foo(days: Days){      let tempDayHolder = days.daysSelected as? String  ?? ""     switch tempDayHolder     {     case "Monday":         outputWeekdays.append(2)     case "Tuesday":         outputWeekdays.append(3)     case "Wednesday":         outputWeekdays.append(4)     case "Thursday":         outputWeekdays.append(5)     case "Friday":         outputWeekdays.append(6)     case "Saturday":         outputWeekdays.append(7)     case "Sunday":         outputWeekdays.append(1)     default :         outputWeekdays.append(1)     } }  var days = Days() foo(days: days) 

code does work (we suppose we got for example for prefs....) I got a waring of unnecessary casting..

2) doing:

    var daysSelected: NSString?{ .. 

and:

let tempDayHolder = days.daysSelected as String? ?? "" 

It does work.

So we need your full code.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment