I have a Swift class Test
with the following initializer.
import Foundation
class Test {
var x: Int
var response: [String: AnyObject]
init(_ x: Int) {
self.x = x
self.response = [String: AnyObject]()
self.y(x)
}
}
Inside Test
, I also have the following method.
func y(_ x: Int) {
// This is a task with a completion handler of type (_, _, _) -> Void
let ... = ...(with: ..., completionHandler: { () in
do {
// The type of z is [String: AnyObject]
let z = ...
self.response = z
} catch {
return
}
})
Calling y
is supposed to reassign z
to self.response
, but self.response
is persistently an empty dictionary.
Am I missing something?