Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Result of initializer is unused

Tags:

swift

swift2

Result of initializer is unused, I get this error in this code:

enter image description here

Changing it like this silences it:

_ = NSURLConnection(request: request, delegate: nil, startImmediately: true)

However it makes the code more uglier, is there a way to silence this warning without using the "_ =" ?

Edit, heres another example:

class SomeView: UIView {
    init(sender: UIViewController) {
        super.init(frame: CGRect(x: 10, y: 10, width: 10, height: 10))
        sender.view.addSubview(self)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        SomeView(sender: self) ///Result of initializer is unused
    }
}

In this example since I am adding the subview from within the view, I do not need to use the created SomeView object in anyway.

like image 955
Esqarrouth Avatar asked Oct 21 '15 12:10

Esqarrouth


1 Answers

Workaround:

NSURLConnection(request: request, delegate: nil)?.start()
like image 165
vadian Avatar answered Sep 24 '22 13:09

vadian