Ich arbeite an einem Firebase Swift-Projekt mit CocoaPods.Wie zu beheben: "Schwerwiegender Fehler: unerwartet gefunden Null beim Entpacken eines optionalen Werts (lldb)"
Jedes Mal, nachdem ich in der Hauptviewcontroller einzuloggen, automatisch erhalte ich EXC_BREAKPOINT
Fehler:
fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)
Hier einige meiner Code-Zeilen sind, wo ich Fehler habe:
All codes from Joke.swift:
import Foundation
import Firebase
class Joke {
private var _jokeRef: Firebase!
private var _jokeKey: String!
private var _jokeText: String!
private var _jokeVotes: Int!
private var _username: String!
var jokeKey: String {
return _jokeKey
}
var jokeText: String {
return _jokeText
}
var jokeVotes: Int {
return _jokeVotes //1
}
var username: String {
return _username
}
// Initialize the new Joke
init(key: String, dictionary: Dictionary<String, AnyObject>) {
self._jokeKey = key
// Within the Joke, or Key, the following properties are children
if let votes = dictionary["votes"] as? Int {
self._jokeVotes = votes
}
if let joke = dictionary["jokeText"] as? String {
self._jokeText = joke
}
if let user = dictionary["author"] as? String {
self._username = user
} else {
self._username = ""
}
// The above properties are assigned to their key.
self._jokeRef = DataService.dataService.JOKE_REF.childByAppendingPath(self._jokeKey)
}
// Add or Subtract a Vote from the Joke.
func addSubtractVote(addVote: Bool) {
if addVote {
_jokeVotes = _jokeVotes + 1
} else {
_jokeVotes = _jokeVotes - 1
}
// Save the new vote total.
_jokeRef.childByAppendingPath("votes").setValue(_jokeVotes)
}
}
In JokeCellTableViewCell.swift :
var joke: Joke!
...............
func configureCell(joke: Joke) {
self.joke = joke
// Set the labels and textView.
self.jokeText.text = joke.jokeText
self.totalVotesLabel.text = "Total Votes: \(joke.jokeVotes)" // 2
self.usernameLabel.text = joke.username
// Set "votes" as a child of the current user in Firebase and save the joke's key in votes as a boolean.
.........
}
Und im Haupt ViewController, JokesFee dTableViewController.swift:
// 1, // 2, // 3 sind Codezeilen, in denen Fehler auftreten.
Ich hoffe, Sie könnten mir helfen, dies zu beheben!
Vielen Dank im Voraus!
Was ist '_jokeVotes '? – Hamish
Mögliches Duplikat von [Schwerwiegender Fehler: unerwartet wurde beim Entpacken eines optionalen Werts null gefunden] (http://stackoverflow.com/questions/24948302/fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-value) – Fonix
@ originaluser2 'var WitzStimmen: Int { zurück _jokeVotes }' _jokeVotes wird als Init –