同时访问0x10f10df48,但修改需要独占访问 [英] Simultaneous accesses to 0x10f10df48, but modification requires exclusive access
本文介绍了同时访问0x10f10df48,但修改需要独占访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在进行SWIFT4迁移,出现此警告(这会使我的应用非常慢)。
同时访问0x10f10df48,但修改需要独占访问。
在线
else if (context == &KVOContext && keyPath == contentSizeKeyPath && object as? UIScrollView == scrollView) {
找不到如何解决此问题。
推荐答案
https://github.com/apple/swift-evolution/blob/master/proposals/0176-enforce-exclusive-access-to-memory.md 在此链接中,您可以看到&;KVOContext
的冲突这样:
// CONFLICT. Passing 'x' as an inout argument is a write access for the
// duration of the call. Passing the same variable twice means performing
// two overlapping write accesses to that variable, which therefore conflict.
swap(&x, &x)
extension Int {
mutating func assignResultOf(_ function: () -> Int) {
self = function()
}
}
我用
解了它struct Pair {
var x: Int
var y: Int
}
class Paired {
var pair = Pair(x: 0, y: 0)
}
let object = Paired()
swap(&object.pair.x, &object.pair.y)
我的代码是
class Paired {
var pair = Pair(x : "PullToRefreshKVOContext")
}
let objects = Paired()
override open func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if (context == &objects.pair.x && keyPath == contentOffsetKeyPath && object as? UIScrollView == scrollView) {
...
}
这篇关于同时访问0x10f10df48,但修改需要独占访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文