When I called the function the only argument I need to passed to is the parameter from start
That's not true.
You have to pass also the closure as second parameter. The closure itself is called by the startUpdates
function after doing its work and passes two parameters back, an optional Data
and an optional Error
instance.
The functional programming is a very convenient way to be able to run arbitrary code (in the closure).
You can declare the closure separately
let result : CMPedometerHandler = { data, error in
if let error = error { print(error); return }
// do something with the data
}
startUpdates(from: Date(), withHandler: result)
or inline
startUpdates(from: Date(), withHandler: { data, error in
if let error = error { print(error); return }
// do something with the data
})
or with trailing closure syntax
startUpdates(from: Date()) { data, error in
if let error = error { print(error); return }
// do something with the data
}