同时访问0x10f10df48,但修改需要独占访问
Posted
技术标签:
【中文标题】同时访问0x10f10df48,但修改需要独占访问【英文标题】:Simultaneous accesses to 0x10f10df48, but modification requires exclusive access 【发布时间】:2018-03-07 11:17:23 【问题描述】:我正在处理 swift4 迁移,但出现了这个警告(这使我的应用程序非常慢)。
。
上线
else if (context == &KVOContext && keyPath == contentSizeKeyPath && object as? UIScrollView == scrollView)
找不到解决办法。
【问题讨论】:
你解决了吗? Simultaneous accesses to 0x1c0a7f0f8, but modification requires exclusive access error on Xcode 9 beta 4的可能重复 【参考方案1】: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,但修改需要独占访问的主要内容,如果未能解决你的问题,请参考以下文章