Simultaneous accesses to 0x1c0a7f0f8, but modification requires exclusive access error on Xcode 9 beta 4

后端 未结 11 1833
孤城傲影
孤城傲影 2020-11-29 05:15

my project uses both Objective-C and Swift code. When a user logs in, it calls a set of apis for user preference, I have a DataCoordinator.swift class which schedules the AP

11条回答
  •  爱一瞬间的悲伤
    2020-11-29 05:43

    In Swift 5.0, this will be the default behavior when running your application in Release mode. Before 5.0 (Swift 4.2.1 as of today and lower) this behavior is only running when in Debug mode.

    Your application will fail in release mode if you ignored this error.

    Consider this example:

    func modifyTwice(_ value: inout Int, by modifier: (inout Int) -> ()) {
      modifier(&value)
      modifier(&value)
    }
    
    func testCount() {
      var count = 1
      modifyTwice(&count) { $0 += count }
      print(count)
    }
    

    What is the value of count, when the print(count) line is printed? Well I don't know either and the compiler gives unpredicatable results when you run this code. This isn't allowed in Swift 4.0 in debug mode and in Swift 5.0 it crashes even in runtime.

    Source: https://swift.org/blog/swift-5-exclusivity/

提交回复
热议问题