I am new to Swift and stuck in a problem.
When I use optional let
inside a class it is giving the error "Class className has no initializers
".
But when I write the same code using optional var
, it shows no error.
For example:
The following code give me error:Class className has no initializers
class className: UIViewController
{
let nearbyPlaceRadius : Int?
override func viewDidLoad()
{
super.viewDidLoad()
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}
}
The following code gives me no error.
class className: UIViewController
{
var nearbyPlaceRadius : Int?
override func viewDidLoad()
{
super.viewDidLoad()
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}
}