'Swift - println Not Printing to Console
The following code either runs or does not run the line println("test"), which results in nothing bring printed to the console:
import UIKit
class ViewController: UIViewController
{
@IBOutlet weak var display: UILabel!
@IBAction func appendDigit(sender: UIButton) {
let digit = sender.currentTitle
println("test")
}
}
Relating to the following GUI:

The following is a screenshot of the console after the program is run and one of the number buttons is pressed:

I do not know if the line of code runs nor why, if it does, that it is not printing to the console.
Can someone please show me how to make it print to the console?
Solution 1:[1]
First, right click a button. Under Sent Events check if there is an event handler set for Touch Up Inside. If so, it might be incompatible with your method appendDigit (wrong parameters maybe?) so you should disconnect it (using the little x).
Next, ctrl-drag from your button to the appendDigit method to hook up the event handler again.
Solution 2:[2]
I know is a litle late but if you're using Swift 2, you can only use print() to write something to the output. Apple has combined both println() and print() functions into one.
If you want to output something with a newline, you can set the appendNewline parameter to true.
Here is an example:
print("Hello new Print with newLine", appendNewline: true)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Steven Van Impe |
| Solution 2 | Jorge Casariego |
