Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unprintable ASCII character found in Swift Source Code

Tags:

xcode

swift

enter image description here

Hi, I am new to Swift language , can anyone explain why there is error with PI Symbol here.

import Foundation

class CalculatorBrain
{

    private var accumulator = 0.0

    func setOperand(operand : Double) {
        accumulator = operand
    }

    func performOperations (symbol: String) {
        switch symbol {
            case "π" :
                accumulator = M_PI
            case "√" :
                accumulator = sqrt(accumulator)
            default : break
        }
    }

    var result : Double {
        get{
            return accumulator
        }
    }
}

reference https://youtu.be/j50mPzDMWVQ?t=2303

like image 465
Abhi Avatar asked Sep 05 '16 10:09

Abhi


3 Answers

In Xcode: "Editor" menu, "Show Invisibles". That will show you invisible characters in your source code.

like image 130
gnasher729 Avatar answered Oct 15 '22 12:10

gnasher729


This answer is for the people who are using windows keyboard with mac system.

While typing you might have unknowingly clicked the right click key in your keyboard, which will create the Unprintable ASCII character that is causing the Unprintable ASCII character found in source file error.

To check this go to find and click the right click key and you can find them in your class and delete those characters and the error will be gone.

Thanks

like image 12
Krishna Vivekananda Avatar answered Oct 15 '22 14:10

Krishna Vivekananda


If you open it in a terminal with an editor such as Vim, you will see that it contains ASCII characters.

enter image description here

like image 2
coffmark Avatar answered Oct 15 '22 14:10

coffmark