Swift: “Use of undeclared type” when trying to push to existing view controller

Swift: “Use of undeclared type” when trying to push to existing view controller



so I'm trying to push to existing view controller on the storyboard programmatically ,but I'm getting Use of undeclared type: LoginViewController even that I set the Storyboard ID to LoginViewController here is my code:


import UIKit

class ViewController: UIViewController

@IBOutlet weak var myButton: UIButton!

@IBAction func Button(_ sender: UIButton)
if let ButtonImage = myButton.image(for: .normal),
let Image = UIImage(named: "ButtonAppuyer.png"),
UIImagePNGRepresentation(ButtonImage) == UIImagePNGRepresentation(Image)

let loginVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
self.navigationController?.pushViewController(loginVC, animated: true)
else
print("OK")



override func viewDidLoad()
super.viewDidLoad()


override func didReceiveMemoryWarning()
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.




Thank you in advance!






what is LoginViewController? is it defined for your target?

– giorashc
Sep 7 '18 at 17:05





1 Answer
1



Make sure you create a new class LoginViewController that inherits from UIViewController.


LoginViewController



To do so go to the File menu > New > File



new file



In the iOS tab, choose Cocoa Touch Class



New Class



And then Next



Give the class name LoginViewController, and make it a subclass of UIViewController


LoginViewController


UIViewController



class name



Click Next and then Create. That will add a new file to your project, and you could/should customize its contents later.



In your storyboard, in the Identity Inspector tab, make sure to set the class name and the identifier to LoginViewController.


LoginViewController



Storyboard






Thank you I’m completely new could you please show me example in the code? Thank you!

– andreydimitro
Sep 7 '18 at 17:11






I got it. Thank you!

– andreydimitro
Sep 7 '18 at 17:32



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

Node.js puppeteer - Use values from array in a loop to cycle through pages