I have written the following code for a protocol. I pass the the reference to the delegate variable and use it to call interface/protocol functions. However, if I put ?
for declaring the Protocol object, no error is generated. If I don't, it gives me an error
property self.delegate is not intialized at super.init().
Why is that?
protocol DownloadDataInterface
{
func downloadCompleted(data : NSDictionary);
}
class DownloadData: NSObject, NSURLConnectionDelegate, NSURLConnectionDataDelegate {
var data : NSMutableData!;
var delegate : DownloadDataInterface;
init(keywords: String!)
{
super.init();
Because by the end of the
init
every property must have been initialized. Either at the declaration site or within the code of theinit
.Properties that are optional or implicitly unwrapped optional are the only exception (because, after all, that's what being optional means).