同时访问0x10f10df48,但修改需要独占访问

2024-02-12

我正在进行 swift4 迁移,并且出现此警告(这使我的应用程序非常慢)。

同时访问0x10f10df48,但修改需要独占访问。

on line

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 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) {
...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

同时访问0x10f10df48,但修改需要独占访问 的相关文章

随机推荐