Attribute being read has no value: 768444

Hello
When I tap on my TextField more than 2/4 times the app crashes
Before that I get these errors:

2020-12-29 11:28:10.265525+0100 Nums[1670:295112] Can't find keyplane that supports type 4 for keyboard iPhone-PortraitChoco-NumberPad; using 25889PortraitChocoiPhone-Simple-PadDefault

2020-12-29 11:28:18.778004+0100 Nums[1670:295112] Can't find keyplane that supports type 4 for keyboard iPhone-PortraitChoco-NumberPad; using 25889
PortraitChocoiPhone-Simple-PadDefault

2020-12-29 11:28:22.268833+0100 Nums[1670:295112] Can't find keyplane that supports type 4 for keyboard iPhone-PortraitChoco-NumberPad; using 25889PortraitChocoiPhone-Simple-Pad_Default

Then after 2/4 four times tapping on the TextField the app crashes and I get this error

2020-12-29 11:28:22.419634+0100 Nums[1670:295112] [error] precondition failure: attribute being read has no value: 768444
AttributeGraph precondition failure: attribute being read has no value: 768444.
(lldb) 

Here is the TextField:

Code Block
GroupBox {
HStack {
TextField("Have a goal?", text: $saveGoal.bound)
.keyboardType(.numberPad)
Spacer()
Button(action: {
UserDefaults.standard.set(self.saveGoal, forKey: "Save") UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}) {
Text("Save")
}
}
}.padding(.top).padding(.trailing).padding(.leading)


Thank you for your time
Answered by Jad-T in 654613022
Ok, Thank you for your time
Do errors occur on simulator or device ?
When does it occur ? When you tap button action ?

On simulator, error message about keyplane is not usually a serious concern. I just ignore
them.

How is self.saveGoal defined and set before calling set ?
What is the content of $saveGoal.bound ?
It happens on a real device
This problem occurs when I close the window without writing anything or tapping done, and other times it crashes just when I close the app

I think this is the real error:
2020-12-29 13:31:50.645517+0100 Nums[2002:352091] [error] precondition failure: attribute being read has no value: 785340

AttributeGraph precondition failure: attribute being read has no value: 785340.

(lldb)

I also get this when I separate the iPhone from the Mac:
warning: failed to set breakpoint site at 0x1a2116b1c for breakpoint -5.1: error sending the breakpoint request

(lldb)

@State private var saveGoal = UserDefaults.standard.string(forKey: "Save")
Are you sure it crashes in the code you posted ?

How is self.saveGoal defined and set before calling set ?
What is the content of $saveGoal.bound ?

Is nums a class of yours ?
I changed it like this (still get errors)
GroupBox {
HStack {
TextField("Have a goal?", text: $saveGoal.bound)
.keyboardType(.numberPad)
Spacer()
Button("Save"){
UserDefaults.standard.set(self.saveGoal, forKey: "Save")
self.hideKeyboard()
}
}


Foe example if I open the textfield and press save without filling the textfield, sometimes it crashes
Or if I close the window while the TextFiled is active

Could you please answer the other questions ?
  • How is self.saveGoal defined and set before calling set ?

  • What is the content of $saveGoal.bound ?

Code Block
GroupBox {
HStack {
TextField("Have a goal?", text: $saveGoal.bound)
.keyboardType(.numberPad)
Spacer()
Button("Save"){
UserDefaults.standard.set(self.saveGoal, forKey: "Save")
self.hideKeyboard()
}
}

@State private var saveGoal = UserDefaults.standard.string(forKey: "Save")
And so, what is $saveGoal.bound ?

Also, saveGoal is an optional, isn't it ?
Code Block
extension Optional where Wrapped == String {
var _bound: String? {
get{
return self
}
set{
self = newValue
}
}
var bound: String {
get{
return _bound ?? ""
}
set {
_bound = newValue.isEmpty ? nil : newValue
}
}
}


Yes SaveGoal is Optional
I edited with formatter
Code Block
extension Optional where Wrapped == String {
var bound: String? {
get {
return self
}
set {
self = newValue
}
}
var bound: String {
get {
return bound ?? ""
}
set {
_bound = newValue.isEmpty ? nil : newValue
}
}
}

So, when you call
Code Block
TextField("Have a goal?", text: $saveGoal.bound)

$saveGoal is optional,
hence bound returns self, which is the optional and may well be nil.

So, I don't understand the logic of extension.
I would have thought the first case to be String
and the second be String?

But I may miss something.
The extension is for the  $saveGoal.bound, because if i delete .bound it gives me errors
Well, you keep answering with very little and cryptic explanation and no full answer to questions or suggestions. The point is not to justify yourself, but provide enough information for others to help.

May be you're tired ? 😉

So, sorry, I give up here.
Can you create a minimized project which can reproduce the issue and show the whole code of it?

AttributeGraph is used under the current implementation of SwiftUI, but it is a private type and we developers know very little of it.
I could not have found exactly the same error on the web. But generally, AttributeGraph precondition failure may be caused by many different reasons and some outer structure may be affecting, such as NavigationView, TabBar, List...

With showing issue reproducible code, someone might be able find a workaround.


Accepted Answer
Ok, Thank you for your time
Attribute being read has no value: 768444
 
 
Q