Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Use of Unresolved Identifier' in Swift

Tags:

xcode

ios

swift

So I have been making an app, and everything has been working great. But today I made a new class like usual and for some reason in this class I can't access Public/Global variable from other classes. All the other classes can, but now when ever I try to make a new class I can't. How would this be fixed?

I am using Swift and Xcode 6.

Working Class:

import UIKit import Foundation import Parse import CoreData  var signedIn = true  class ViewController: UIViewController { 

New Class:

import UIKit  class NewClass: UIViewController {      override func viewDidLoad() {         super.viewDidLoad()          signedIn = false  } 

But on signedIn = false

I get the error:

use of unresolved identifier "signedIn"

like image 780
Apple Geek Avatar asked Mar 11 '15 20:03

Apple Geek


People also ask

What is use of unresolved identifier?

Use of unresolved identifier is such a compile-time error, because the error arises when compiling your app. Conversely, a run-time error is an error that occurs while you run your app. So… Use of unresolved identifier really means: “You're using a framework, class, function, property, or variable Xcode doesn't know!”

What does undeclared identifier mean in C++?

The identifier is undeclared: In any programming language, all variables have to be declared before they are used. If you try to use the name of a such that hasn't been declared yet, an “undeclared identifier” compile-error will occur. Example: #include <stdio.h> int main()


Video Answer


2 Answers

One possible issue is that your new class has a different Target or different Targets from the other one.

For example, it might have a testing target while the other one doesn't. For this specific case, you have to include all of your classes in the testing target or none of them.

Targets

like image 199
lchamp Avatar answered Sep 22 '22 10:09

lchamp


Once I had this problem after renaming a file. I renamed the file from within Xcode, but afterwards Xcode couldn't find the function in the file. Even a clean rebuild didn't fix the problem, but closing and then re-opening the project got the build to work.

like image 35
ThomasW Avatar answered Sep 21 '22 10:09

ThomasW