Simultaneous accesses to 0x6040000155d8, but modification requires exclusive access
You should try updating this line
createGameModel?.createGameOptions?.removeSubrange(2...((createGameModel?.createGameOptions?.count)! - 2))
To
let count = (createGameModel?.createGameOptions?.count)!
createGameModel?.createGameOptions?.removeSubrange(2...(count - 2))
Try and share the results
Simultaneous accesses to 0x14572f2a0, but modification requires exclusive access
This is what you get for testing the code in a playground — there's no debugger! If you try that code in a real app, the debugger tells you exactly what the problem is.
The problem is here:
public func withdraw(amount: Float) -> Bool {
return state.withdraw(amount: amount) // <-- *
}
The withdraw state's withdraw
method sets the state
property of its context
, which is this ATM instance. So the call to state.withdraw
means that we both mutate this ATM's state value directly, by replacing it with a different state object, and call its mutating method withdraw
, in a single move. You can't do that, because the double mutation, to a property of the struct and to a reference to the struct as a whole, is incoherent. You have to proceed in stages, like this:
public func withdraw(amount: Float) -> Bool {
// fetch
var theState = self.state
// mutate
return theState.withdraw(amount: amount)
}
The alternative would be to make all of the state types classes instead of structs. A class, unlike a struct, is mutable in place. That would require considerably more rewriting, however, so that is left as an exercise for the reader.
SwiftUI @AppStroage - 'Simultaneous accesses to *, but modification requires exclusive access'
I am going to attribute this to a SwiftUI bug. I have submitted it to Apple (FB9975464). The issue seemed to be in the CrashSetting
initializer, but it actually occurs without it. I believe the issue is using the dot (.
) character in the AppStorage key. It has also caused [error] precondition failure: setting value during update: 5848
. I haven't been able to produce a small demo with that crash, but removing the "." from my keys also solves it. If you experience any of the above, specifically while transitioning/navigating views, it's worth checking your AppStorage keys.
Simplest Crash Demo
- Build on iPad mini
- Tap Back button
import SwiftUI
@main
struct AppStorage_Key_IssueApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
// Using the "." character results in many hard to track crashes
@AppStorage("a.b")
var val = ""
var body: some View {
NavigationView {
PrimaryView()
Color.blue
}
}
}
struct PrimaryView: View {
var body: some View {
List {
NavigationLink {
Color.red
} label: {
Text("crashes")
}
}
.listStyle(InsetGroupedListStyle())
}
}
Thread 5: Simultaneous accesses to 0x10b883638, but modification requires exclusive access
Try this code:
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
// Only handle observations for the playerItemContext
guard context == &P2SheetViewController.playerStatusContext else {
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
return
}
if keyPath == #keyPath(AVPlayer.status) {
let status: AVPlayer.Status
if let statusNumber = change?[.newKey] as? NSNumber {
status = AVPlayer.Status(rawValue: statusNumber.intValue)!
} else {
status = .unknown
}
//Switch over status value
switch status {
case .readyToPlay:
break
// Player item is ready to play
case .failed:
print(".UKNOWN")
break
// Player item failed. See error.
case .unknown:
print(".UKNOWN")
break
// Player item is not yet ready.
@unknown default: //new jul 17
print(".UKNOWN")
break
}
}
}
Hope it helps
Related Topics
What Is _: in Swift Telling Me
Detect When a Tab Bar Item Is Pressed
Dynamically Hiding View in Swiftui
Call a Method from a String in Swift
Get Integer Value from String in Swift
Swift 3 For Loop With Increment
How to Apply the Type to a Nsfetchrequest Instance
Swift Dictionary Get Key For Value
Unexpected Non-Void Return Value in Void Function (Swift 2.0)
Does Swift Have Documentation Generation Support
Uialertcontroller - Add Custom Views to Actionsheet
Fetch Data from Coredata For iOS 14 Widget