2017-09-26 39 views
1

我正在進行swift4遷移併發出此警告(使我的應用非常緩慢)。同時訪問0x10f10df48,但修改需要獨佔訪問

同時訪問0x10f10df48,但修改需要獨佔訪問。

上線

else if (context == &KVOContext && keyPath == contentSizeKeyPath && object as? UIScrollView == scrollView) { 

無法找到如何解決它。

+0

你解決了這個問題嗎? – Glenn

+0

[可同時訪問0x1c0a7f0f8,但修改需要Xcode 9 beta 4上的獨佔訪問錯誤](https://stackoverflow.com/questions/45415901/simultaneous-accesses-to-0x1c0a7f0f8-but-modification-requires-exclusive -訪問) – the4kman

回答

0

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() 
    } 
} 

我解決它通過

​​

我的代碼是

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) { 
... 
}