According to objective-c documentation of PFUser.currentUser(), which I'm assuming translates into a Swift optional, it could easily return nil. So you need to do something like:
if let currentUser = PFUser.currentUser() {
query.whereKey("accepted", equalTo: currentUser.username)
if let someArrayObject = currentUser["accepted"] as? [AnyObject] {
query.whereKey("username", containedIn: someArrayObject)
}
} else {
// currentUser does not exist, do error handling
}
Not sure what that second query
line is, and what the someArrayObject
is, so you might look further into that. But your error is either related to you dereferencing the currentUser()
which could be nil, or the use of as
and not as?
in the second query
line.
Solution to either is to use proper unwrapping of the potential optional values.