I'm new to swift. when I'm learning just basics I got this error at NSLog
Here is my code :
import UIKit
class ViewController: UIViewController {
var myString: NSString?
override func viewDidLoad() {
super.viewDidLoad()
myString = "himanth"
print(myString)
NSLog("%@" , myString)
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
If I am declaring myString
like this
var myString: NSString!
It's fine to use NSLog
and I can able to see console as well.
But declaring string like this causing problem
var myString: NSString?
It reflects at NSLog
and showing error.
What is the problem with that?
NSLog("%@", myString ?? "<nil>")
surely? – Fyke