vendredi 27 mars 2020

Error: 'Missing return in a function expected to return Int'

The first function below works fine to check for FM values, but when I added some validation in an else if statement for the AM values, I am getting error message saying: Missing return in a function expected to return Int. It doesn't seem to be an issue with the placement of the curly braces.

        static var minAMFFrequency: Double = 520.0
        static var maxAMFFrequency: Double = 1610.0
        static var minFMFFrequency: Double = 88.3
        static var maxFMFFrequency: Double = 107.9

    func isBandFM() -> Int {
        if frequency >= RadioStation.minFMFFrequency && frequency <= RadioStation.maxFMFFrequency {
            return 1 //FM
        } else {
            return 0 //AM
        }
    }

Modified function with error:

func isBandFM() -> Int {
        if frequency >= RadioStation.minFMFFrequency && frequency <= RadioStation.maxFMFFrequency {
            return 1 //FM
        } else if frequency >= RadioStation.minAMFFrequency && frequency <= RadioStation.maxAMFFrequency{
            return 0 //AM
        }
    }

Aucun commentaire:

Enregistrer un commentaire