问题
From the doc we should be using:
DispatchQueue(label: "background").async {
autoreleasepool {
let realm = try! Realm()
let theDog = realm.objects(Dog.self).filter("age == 1").first
try! realm.write {
theDog!.age = 3
}
}
}
However, that usage seems exactly how the following does:
DispatchQueue(label: "background", autoreleaseFrequency: .workItem).async {
let realm = try! Realm()
let theDog = realm.objects(Dog.self).filter("age == 1").first
try! realm.write {
theDog!.age = 3
}
}
Could someone confirm the second approach works as expected?
来源:https://stackoverflow.com/questions/49459967/for-realm-swift-could-i-use-dispatchqueue-with-autorelease-frequency-of-workit