3

I'm working on swift4 migration and this warning (that make my app very slow) appears.

Simultaneous accesses to 0x10f10df48, but modification requires exclusive access.

on line

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

Can't found how to solve it.

Makaille
  • 1,636
  • 2
  • 24
  • 41
  • Have you solved this? – Glenn Posadas Oct 04 '17 at 07:42
  • Possible duplicate of [Simultaneous accesses to 0x1c0a7f0f8, but modification requires exclusive access error on Xcode 9 beta 4](https://stackoverflow.com/questions/45415901/simultaneous-accesses-to-0x1c0a7f0f8-but-modification-requires-exclusive-access) – Tamás Sengel Oct 05 '17 at 13:30

1 Answers1

1

https://github.com/apple/swift-evolution/blob/master/proposals/0176-enforce-exclusive-access-to-memory.md In this link you can see the conflict of &KVOContext

like this:

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

I solved it by

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)

My code is

    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) {
...
}
muxue wei
  • 11
  • 1