日々精進

新しく学んだことを書き留めていきます

delegateにオブジェクトを代入すると「Cannot assign to the result of this expression」エラー

以下のように、delegateに代入するとエラーになる。

self.urlDownloader?.delegate = self

以下のようにunwrapすると直る。

self.urlDownloader!.delegate = self

以下のサイトの記事ではこの原因は「self.urlDownloader?を評価した結果、nilになることがあるため」と推測している。
optionalが代入式の左についていたらエラーになるっぽい。
参考:Cannot assign to the result of this expression error in Swift