import UIKit
class ViewController: UIViewController {
var testArray:[String] = []
override func viewDidLoad() {
super.viewDidLoad()
doThis(nil)
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func doThis(completion:(() -> Void)?) {
dispatch_async(dispatch_get_main_queue(), {() -> Void in
if let completionBlock = completion {
completionBlock()
}
self.testArray.append("first")
print(self.testArray)
if self.testArray == [] {
print("has data")
} else {
print("null")
}
})
}
}
Output:
["first"]
null
I was wondering why the array is nil
?