Xcode Gives False '{' missing in class error

Xcode says a curly bracket is missing at the end of my class, but it's not here's my code.
Xcode says that { is missing in my class, but it's not, which causes other errors at the @objc private functions saying attribute private can only be used in a non-local scope, and also gives another error at my extensions saying declaration is only valid at file scope, here's my code.

import UIKit
import Foundation
import Firebase
import FirebaseDatabase
import FirebaseAuth
import GoogleSignIn
import FBSDKLoginKit
import SCLAlertView
import UserNotifications
import FirebaseStorage


class SignupViewController: UIViewController {
Code Block
@IBOutlet weak var usernameTextfield: UITextField!
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var reenterPasswordTextField: UITextField!
@IBOutlet weak var signupButton: UIButton!
@IBOutlet weak var errorlabel: UILabel!
@IBOutlet weak var passwordEye: UIImageView!
@IBOutlet weak var cameraButton: UIImageView!
@IBOutlet weak var googleBtn: UIButton!
@IBOutlet weak var fbBtn: UIButton!
var database: DatabaseReference!
private let storage = Storage.storage().reference()
override func viewDidLoad() {
super.viewDidLoad()
database = Database.database().reference()
}
func aftersuccess(){
passwordTextField.isSecureTextEntry = true
reenterPasswordTextField.isSecureTextEntry = true
GIDSignIn.sharedInstance().presentingViewController = self
passwordEye.isUserInteractionEnabled = true
passwordEye.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(eyeSelected)))
setUpElements()
cameraButton.isUserInteractionEnabled = true
cameraButton.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(cameraButtonPressed)))
let spacerView = UIView(frame:CGRect(x:0, y:0, width:30, height:10))
passwordTextField.leftViewMode = UITextField.ViewMode.always
passwordTextField.leftView = spacerView
let spacerView2 = UIView(frame:CGRect(x:0, y:0, width:30, height:10))
emailTextField.leftViewMode = UITextField.ViewMode.always
emailTextField.leftView = spacerView2
let spacerView3 = UIView(frame:CGRect(x:0, y:0, width:30, height:10))
reenterPasswordTextField.leftViewMode = UITextField.ViewMode.always
reenterPasswordTextField.leftView = spacerView3
let spacerView4 = UIView(frame:CGRect(x:0, y:0, width:30, height:10))
usernameTextfield.leftViewMode = UITextField.ViewMode.always
usernameTextfield.leftView = spacerView4
cameraButton.layer.masksToBounds = true
cameraButton.layer.cornerRadius = 80
cameraButton.contentMode = .scaleToFill
googleBtn.layer.cornerRadius = googleBtn.frame.width/2
googleBtn.layer.masksToBounds = true
fbBtn.layer.cornerRadius =
fbBtn.frame.width / 2
fbBtn.layer.masksToBounds = true
guard let urlString = UserDefaults.standard.value(forKey: "url") as? String,
let url = URL(string: urlString) else {
return
}
let task = URLSession.shared.dataTask(with: url, completionHandler: { data, _, error in
guard let data = data, error == nil else{
return
}
DispatchQueue.main.async {
let image = UIImage(data: data)
self.cameraButton.image = image
}
})
task.resume()
}
override func viewWillDisappear(_ animated: Bool) {
aftersuccess()
}
override func viewWillAppear(_ animated: Bool) {
aftersuccess()
}
func setUpElements() {
//Hides error label
errorlabel.alpha = 0
}
func validateFields() -> String? {
if usernameTextfield.text?.trimmingCharacters(in: .whitespacesAndNewlines) == "" || emailTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) == "" {
SCLAlertView().showError("Try Again",subTitle:"😱Please fill in all of the fields😱")
}
let cleanedPassword = passwordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
if Utilities.isPasswordValid(cleanedPassword) == false {
SCLAlertView().showError("Try Again",subTitle:"😱Please make sure your password is at least 8 characters, contains a special character, and a number.😱")
}
return nil
}
@IBAction func didChangeSegement(_ sender:UISegmentedControl){
if sender.selectedSegmentIndex == 1{
let vc = storyboard?.instantiateViewController(identifier: "loginVC") as! LoginViewController
vc.modalPresentationStyle = .fullScreen
present(vc, animated: true)
}
}
@IBAction func signUpTapped(_ sender: UIButton) {
let error = validateFields()
if error != nil {
sender.shake()
SCLAlertView().showError("Uh Oh",subTitle:"Something went wrong")
}else if reenterPasswordTextField.text! != passwordTextField.text!{
sender.shake()
SCLAlertView().showError("Try Again",subTitle:"😱Your passwords do not match.😱")
}else {
let username = usernameTextfield.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let email = emailTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let password = passwordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
// DatabaseManager.shared.userExists(with: email, completion: { exists in
// if !exists{
//
// }
// })
}
}
Code Block
func transitionToHome() {
let homeViewController = storyboard?.instantiateViewController(identifier: Constants.Storyboard.homeViewController) as? HomeViewController
view.window?.rootViewController = homeViewController
view.window?.makeKeyAndVisible()
}
@objc private func eyeSelected(){
passwordTextField.isSecureTextEntry.toggle()
if passwordTextField.isSecureTextEntry == true{
passwordEye.image = UIImage(systemName: "eye")
}else{
passwordEye.image = UIImage(systemName: "eye.fill")
}
}
@IBAction func googleBtnPressed(_ sender: Any) {
if GIDSignIn.sharedInstance()?.currentUser != nil{
}else{
GIDSignIn.sharedInstance()?.signIn()
if let user = GIDSignIn.sharedInstance()?.currentUser{
DatabaseManager.shared.userExists(with: user.profile.email, completion: { exists in
guard !exists else{
SCLAlertView().showError("Oof",subTitle:"😱Someone with this account already exists😱")
return
}
DatabaseManager.shared.insertUser(with: UserModel(username: user.profile.name, email: user.profile.email, password: "null (Google Sign In)", profilePictureURL: "nil"))
GIDSignIn.sharedInstance()?.presentingViewController = self
let homeViewController = self.storyboard?.instantiateViewController(identifier: "homeVC") as! HomeViewController
homeViewController.modalPresentationStyle = .fullScreen
self.present(homeViewController, animated: true)
})
}
}
}
@IBAction func fbBtnPressed(_ sender: Any) {
let fbLoginManager = LoginManager()
fbLoginManager.logIn(permissions: ["public_profile", "email"], from: self) { (result, error) in
if error != nil {
SCLAlertView().showError("Oof",subTitle:"😱Error signing you in.😱")
return
}
guard let accessToken = AccessToken.current else {
SCLAlertView().showError("Oof",subTitle:"😱Try again without Facebook😱")
return
}
let credential = FacebookAuthProvider.credential(withAccessToken: accessToken.tokenString)
Auth.auth().signIn(with: credential, completion: { (user, error) in
if error != nil {
SCLAlertView().showError("Oof",subTitle:"😱Error signing you in.😱")
return
}
else {
let user = Auth.auth().currentUser!
DatabaseManager.shared.userExists(with: user.email!, completion: { exists in
guard !exists else{
SCLAlertView().showError("Oof",subTitle:"😱Someone with this account already exists😱")
return
}
DatabaseManager.shared.insertUser(with: UserModel(username:user.displayName!, email: user.email!, password: "null (Facebook Sign In)", profilePictureURL: "null"))
let homeViewController = self.storyboard?.instantiateViewController(identifier: "homeVC") as! HomeViewController
homeViewController.modalPresentationStyle = .fullScreen
self.present(homeViewController, animated: true)
})
}
})
}
}
@objc private func cameraButtonPressed(){
presentPhotoActionSheet()
}
}

extension SignupViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
Code Block
func presentPhotoActionSheet(){
let actionSheet = UIAlertController(title: "Profile Picture", message: "Which way would you like to select a profile picture", preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction(title: "Cancel", style: .destructive, handler:nil))
actionSheet.addAction(UIAlertAction(title: "Take Photo", style: .default, handler: { [ weak self ] _ in
self?.presentCamera()
}))
actionSheet.addAction(UIAlertAction(title: "Choose Photo", style: .default, handler: { [ weak self ] _ in
self?.presentPhotoPicker()
}))
present(actionSheet, animated: true)
}
func presentCamera(){
let vc = UIImagePickerController()
vc.sourceType = .camera
vc.delegate = self
vc.allowsEditing = true
present(vc, animated: true)
}
func presentPhotoPicker(){
let vc = UIImagePickerController()
vc.sourceType = .photoLibrary
vc.delegate = self
vc.allowsEditing = true
present(vc, animated: true)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
picker.dismiss(animated: true, completion: nil)
print(info)
guard let selectedImage = info[UIImagePickerController.InfoKey.editedImage] as? UIImage else{
return
}
guard let imageData = selectedImage.pngData() else{
return
}
storage.child("images/" + "filename" + ".png").putData(imageData, metadata: nil, completion: { _, error in
guard error == nil else{
SCLAlertView().showError("Image can't be uploaded",subTitle:"😱Please choose another image😱")
return
}
self.storage.child("images/file.png").downloadURL(completion: { url, error in
guard let url = url, error == nil else{
return
}
let urlString = url.absoluteString
UserDefaults.standard.set(urlString, forKey: "url")
})
})
self.cameraButton.image = selectedImage
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker.dismiss(animated: true, completion: nil)
}
}

Answered by OOPer in 665830022
Your code is not properly formatted, so I cannot say if your code has some issue or not.
Please try editing (or re-posting) your post with using Code block feature (icon <>).

But Xcode often recalls old errors, so you may be seeing just an old error message.
Have you tried Clean Build Folder or restarting your Xcode and Mac?
Accepted Answer
Your code is not properly formatted, so I cannot say if your code has some issue or not.
Please try editing (or re-posting) your post with using Code block feature (icon <>).

But Xcode often recalls old errors, so you may be seeing just an old error message.
Have you tried Clean Build Folder or restarting your Xcode and Mac?
I copied the full code in playground (after properly editing). No such error.

What is the exact and complete message you get ?

Are you based in Fort Smith ? 😉
I get, 'Attribute private can only be used in a non-local scope' near the @objc, and 'declaration is only valid at file scope' near the extension, and 'Expected '}' in class' at the end of the file
I am not based in Fort Smith, I am based in Northern Virginia
I thought that was the zip code, bad guess.

near the @objc

Is it eyeSelected() ?

I could not reproduce your issue.
You should probably comment out all the func in the class, until you just get the class declaration and see wifi the error disappear.

Then reintroduce func one by one.
I fixed the error, I had a duplicated class in my app, and I used it in the file that was causing the errors, which broke Xcode.
Xcode Gives False '{' missing in class error
 
 
Q