0

I have what I think should be a very simple operation. I just want to have an entry in a Firebase DB changed when I press a button. I already checked that there's nothing wrong with the button.

Here is my FireBase entry, by the way:

enter image description here

This code works fine in displaying text to the console (so, no problem with the button or connection, or variable, for that matter):

   @IBAction func test(_ sender: Any) {
    print("Username: \(requestUsername)")
   }

My simple IBAction function gets a SIGABRT every time. I tried to look at other S.O. questions on the best way to update values, and to try to follow their suggestions, so I'm not sure if my firebase code is messed up, or something else. Right now, "ref" is declared inside the IBAction, but I've also tried declaring it globally, with the same result.

   @IBAction func test(_ sender: Any) {

    var ref = FIRDatabase.database().reference()
    ref.child("Sell_Request").child(requestUsername).child("Request_Made").setValue("true")

    }

Update:

For what it's worth, I'm able to get the correct Firebase entry with this code. I'm still not sure how to update specific fields. If anyone has any ideas, I would appreciate it.

ref.child("Sell_Request").queryOrdered(byChild: "name").queryEqual(toValue: requestUsername).observeSingleEvent(of: .value, with: { (snapshot) in
                print(snapshot)
            })
        }
user2411290
  • 631
  • 2
  • 10
  • 33
  • Can you paste the actual error from the console? – Pratik Patel Mar 03 '17 at 20:32
  • This is what I'm getting: libc++abi.dylib: terminating with uncaught exception of type NSException – user2411290 Mar 03 '17 at 20:39
  • Your button is referencing something that doesn't exist anymore. Look at the stoyboard and make sure to remove the connection that is not valid anymore. http://stackoverflow.com/questions/26442414/libcabi-dylib-terminating-with-uncaught-exception-of-type-nsexception-lldb – Pratik Patel Mar 03 '17 at 21:06
  • I actually did a test and printed to the console, so it's not that. I think the answer is that when I look for .child(requestUsername), it is expecting an ID, and not a username. – user2411290 Mar 03 '17 at 21:15

0 Answers0