-3

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

Has
  • 885
  • 4
  • 13
  • 31
  • What's the error? And part all code as text here directly. – Carcigenicate Nov 11 '17 at 15:19
  • 1. Did it? 2. How did you declare outputString/outputWeekdays? – Lou Franco Nov 11 '17 at 15:19
  • I am not 100% sure. I thought that is where it is crashing as there is a red ribbon there (as per the screenshot). How can I know exactly where the code is crashing ? The app seems to work fine in the simulator. However in real life on the iphone, it is crashing. – Has Nov 11 '17 at 15:58
  • Hi All, I've updated the original question with a deeper crash log. Would be grateful for any pointers please. As for outputString, it is defined as a string in the tableView. Thanks. – Has Nov 11 '17 at 21:51
  • @Has you should use SYM file to give a clearer crash log https://stackoverflow.com/questions/25855389/how-to-symbolicate-crash-log-xcode – trungduc Nov 14 '17 at 17:13

1 Answers1

0

(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.

erik_m_martens
  • 496
  • 3
  • 8
ingconti
  • 10,876
  • 3
  • 61
  • 48