I am getting my value as Value comes as optional("myvalue"),But how can i get only value without the optional. I have tried a lot but not getting point, any help will be appreciated highly. The thing is that i am using Firebase as database and getting values in database.
I want to get value of Gender, Blood and country code.
Firebase connectivity
ref.child("user_registration").child(UserID!).setValue(["username": fullName.text!, "email": emailTextField.text!, "contact": numberText.text!, "city": myCity.text!, "state":countryText.text!, "gender": genderGroup, "blood": bloodGroup,"code": countryGroup])
Other code
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == tableViewB {
let cell = tableViewB.dequeueReusableCell(withIdentifier: "blood", for: indexPath)
cell.textLabel!.text = dropDownList[indexPath.row]
return cell
}
else if tableView == genderT {
let cell = genderT.dequeueReusableCell(withIdentifier: "gender", for: indexPath)
cell.textLabel!.text = genderL[indexPath.row]
return cell
}
else {
let cell = countryT.dequeueReusableCell(withIdentifier: "country", for: indexPath) as! CountryTableViewCell
cell.countryLabel.text = countryL[indexPath.row]
cell.flagImage.image = countryFlags[indexPath.row]
return cell
}
}
var bloodGroup : String?
var genderGroup : String?
var countryGroup : String?
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if tableView == tableViewB {
let selectedData = dropDownList[indexPath.row]
buttonB.setTitle(selectedData, for: .normal)
self.tableViewB.isHidden = true
self.flag = 1
let indexPath = tableViewB.indexPathForSelectedRow
let currentCell = tableViewB.cellForRow(at: indexPath!)! as UITableViewCell
bloodGroup = currentCell.textLabel!.text!
print("\(bloodGroup)")
}
else if tableView == genderT {
let selectedDataG = genderL[indexPath.row]
genderB.setTitle(selectedDataG, for: .normal)
self.genderT.isHidden = true
self.flag = 1
let indexPath = genderT.indexPathForSelectedRow
let currentCell = genderT.cellForRow(at: indexPath!)! as UITableViewCell
genderGroup = currentCell.textLabel!.text!
print("\(genderGroup)")
}
else {
let selectedDataG = countryL[indexPath.row]
countryB.setTitle(selectedDataG, for: .normal)
self.countryT.isHidden = true
self.flag = 1
let indexPath = countryT.indexPathForSelectedRow
let currentCell = countryT.cellForRow(at: indexPath!)! as! CountryTableViewCell
countryGroup = currentCell.countryLabel.text!
let finalFlag = currentCell.flagImage.image!
print("\(finalFlag)" + "\(countryGroup)")
}
}
<br>
Console
com.apple.MobileAsset.TextInput.SpellChecker
Optional("male")
Optional("A+")
<UIImage: 0x600000295950>, {96, 64}Optional("+92")
fatal error: unexpectedly found nil while unwrapping an Optional value