Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Http request on iOS app starting

Tags:

ios

swift

I want to send http request on every myapp-starting. How to do this? I try:

class MainViewController: UITableViewController {
func my_request(){

        let url = NSURL(string: "http://www.stackoverflow.com")
        let request = NSURLRequest(URL: url)
        let connection = NSURLConnection(request: request, delegate:nil, startImmediately: true)
        println(connection)

        }

        let lol = my_request()
}

But I have an error: Missing argument for parameter #1 in call

How to fix that?

Thanks!

like image 428
Lev Avatar asked Apr 13 '26 21:04

Lev


1 Answers

my_request() returns nothing, if you just want to call the function, use only

my_request()

I would suggest to put this in the ViewDidLoad function (on your Main ViewController of your App)

like image 113
derdida Avatar answered Apr 16 '26 19:04

derdida



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!