Swift - How to make and run an Assynctask?

Asked

Viewed 83 times

0

I made an app on Android and am making a version of it for IOS currently, I would like to know how I could implement an Assynctask on Swift and run.

On Android I did this way:

public void carregaBanner2(){ new LongOperation3().execute("");}
private class LongOperation3 extends AsyncTask<String, Void, String> {
    public char getChar(char x){return x;}
    @Override
    protected String doInBackground(String... params) {
        try {
            //o que quero executar. . .
            Thread.sleep(1000);
        } catch (Exception e) {
            Log.e("log_tag", "Error in http connection "
                    + e.toString());
        }
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        try {
            //depois de executado. . .
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onPreExecute() {
        //Antes de executar. . .
    }

    @Override
    protected void onProgressUpdate(Void... values) {
    }
}

1 answer

1

I believe you are looking for a feature called Grand Central Dispatch (GCD), which takes care of the competition on Swift. Take a look here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.