O'Reilly logo

Mastering Swift 4 - Fourth Edition by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Calculation type

Before we look at how to use the dispatch queues, let's create a class that will help us demonstrate how the various types of queues work. This class will contain two basic functions and we will name the class DoCalculations. The first function will simply perform some basic calculations and then return a value. Here is the code for this function, which is named doCalc():

func doCalc() {  
  var x = 100 
  var y = x*x 
  _ = y/x 
} 

The other function, which we will name performCalculation(), accepts two parameters. One is an integer named iterations and the other is a string named tag. The performCalculation() function calls the doCalc() function repeatedly until it calls the function the same number of times as defined by the iterations ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required