let vc = self.storyboard?.instantiateViewController(withIdentifier: "NewRecipeVC")as! NewRecipe
present(vc ,animated: true)
I’m wondering if Xcode is struggling to diffrentiate between NewRecipe in your let statement and NewRecipe in your cast statement. Also it’s possible that the complier is also confused where you have used NewRecipe in your present() statement.
I’ve just cobbled up some code to check that what you are doing makes sense and as long as you have the name correct in your Storyboard ID (the Identifier) for that target ViewController it should work.
I’m a bit fussy about naming things and I would have named that NewRecipe to be NewRecipeViewController but that’s your choice. It just makes it clear as to what it is.
So in my calling ViewContoller I have a simple Button that you tap and present it:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func newRecipeTapped(_ sender: Any) {
if let vc = storyboard?.instantiateViewController(withIdentifier: "newRecipeVC") as? NewRecipeViewController {
present(vc, animated: true)
}
}
}
In the NewRecipeViewController I have a label in the middle so I know that I have the right one and the view.backgroundColor = .red
class NewRecipeViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.backgroundColor = .red
}
}
@Chris_Parker i have changed it all to look the same as yours, i think i might swap it over to a fresh project, i have only written about 50 lines. and i was messing around with stuff earlier on it to see if i could get it to work myself.ill reply back to this convo if it works on a new project
@Ru55_2
Before you throw the original project in the bin, can you try cleaning it (Shift + Command + K) and see if that restores some kind of sensibility?
@Chris_Parker i tried doing the Shift + command + K on the new project, but I’m still getting the same error.
do you think that other things i wrote are causing the error?
this is the rest of my code i have:
import Firebase
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
text.backgroundColor = .white
text.textColor = .black
text.autocapitalizationType = .words
text.clearsOnBeginEditing = true
}
let db = Firestore.firestore()
@IBOutlet weak var text: UITextField!
@IBAction func SearchButton(_ sender: Any) {
text.resignFirstResponder()
Check(name: text.text!)
}
func Check(name : String){
let recipes = db.collection("Recipe")
let query = recipes.whereField("recipes", in: [name])
query.getDocuments { (querySnapshot, error) in
if let error = error {
print(error.localizedDescription)
} else {
if querySnapshot!.documents.isEmpty {
print("No data Found")
self.createrecipe()
} else {
// Loop through documents and print data.
for doc in querySnapshot!.documents {
print(doc.data())
}
}
}
}
}
func createrecipe(){
if let vc = self.storyboard?.instantiateViewController(withIdentifier: "NewRecipeVC")as? NewRecipeViewController{
present(vc,animated: true)
}
}
}```
Can you share your project via DropBox or GoogleDrive and I’ll take a look for you. I’m just at home convalescing so something to keep me occupied is welcome.