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?
所以我一直在做一个应用,一切都很好。但是今天我创建了一个新的类,像往常一样,由于某些原因,我不能从其他类访问Public/Global变量。所有其他的课程都可以,但是现在当我尝试创建一个新的课程时,我不能。如何解决这个问题?
I am using Swift and Xcode 6.
我正在使用Swift和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
但是在signedIn = false上
I get use of unresolved identifier signedIn
我使用了未解析的标识符signedIn。
10 个解决方案
#1
205
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.
例如,它可能有一个测试目标,而另一个没有。对于这个特定的情况,您必须在测试目标中包含所有的类,或者不包含任何类。
#2
2
For me this error happened because I was trying to call a nested function. Only thing I had to do to have it fixed was to bring the function out to a scope where it was visible.
对我来说,这个错误发生是因为我试图调用一个嵌套函数。我要做的唯一一件事就是把这个函数放到一个可见的范围内。
#3
1
Because you haven't declared it. If you want to use a variable of another class you must use
因为你还没有声明。如果您想要使用另一个类的变量,则必须使用。
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var DestViewController : ViewController = segue.destinationViewController as ViewController
DestViewController.signedIn = false
}
You have to put this code at the end of the NewClass code
您必须将此代码放在NewClass代码的末尾
#4
1
Sometimes the compiler gets confused about the syntax in your class. This happens a lot if you paste in source from somewhere else.
有时编译器会对类中的语法感到困惑。如果从其他地方粘贴源文件,这种情况经常发生。
Try reducing the "unresolved" source file down to the bare minimum, cleaning and building. Once it builds successfully add all the complexity back to your class.
尝试将“未解决”的源文件减少到最少,清理和构建。一旦构建成功,将所有的复杂性添加回类中。
This has made it go away for me when re-starting Xcode did not work.
这使我在重新启动Xcode失败时不再使用它。
#5
1
Your NewClass
inherits from UIViewController
. You declared signedIn
in ViewController
. If you want NewClass
to be able to identify that variable it will have to be declared in a class that your NewClass
inherits from.
你的NewClass继承自UIViewController。你在ViewController中声明signedIn。如果希望NewClass能够识别该变量,则必须在NewClass继承的类中声明它。
#6
#7
0
Another place I've seen this error is when your project has multiple targets AND multiple bridging headers. If it's a shared class, make sure you add the resource to all bridging headers.
我看到的另一个错误是当您的项目有多个目标和多个桥接头时。如果是共享类,请确保将资源添加到所有桥接头。
A good tip to is to look in the left Issue Navigator panel; the root object will show the target that is issuing the complaint.
一个很好的技巧是查看左边的问题导航面板;根对象将显示发出投诉的目标。
#8
0
If this is regarding a class you created, be sure that the class is not nested.
如果这与您创建的类有关,请确保该类没有嵌套。
F.e
F.e
A.swift
A.swift
class A {
class ARelated {
}
}
calling var b = ARelated()
will give 'Use of unresolved identifier: ARelated'.
调用var b = ARelated()将给出“使用未解析标识符:ARelated”。
You can either:
你可以:
1) separate the classes if wanted on the same file:
1)在同一个文件中,如果需要,将类分开:
A.swift
A.swift
class A {
}
class ARelated {
}
2) Maintain your same structure and use the enclosing class to get to the subclass:
2)保持相同的结构,使用封闭类到达子类:
var b = A.ARelated
var b = A.ARelated
#9
0
I did a stupid mistake. I forgot to mention the class as public or open while updating code in cocoapod workspace.
我犯了一个愚蠢的错误。在更新cocoapod工作空间中的代码时,我忘记将类作为公共的或开放的。
Please do check whether accesor if working in separate workspace.
请检查是否在单独的工作区工作。
#10
0
I got this error for Mantle Framework in my Objective-Swift Project. What i tried is ,
在我的Objective-Swift项目中,我得到了地幔框架的错误。我尝试的是,
- Check if import is there in Bridging-Header.h file
- 检查桥联页眉中是否有导入。h文件
- Change the Target Membership for Framework in Mantle.h file as shown in below screenshot.
- 在地幔中改变框架的目标成员。h文件如下截图所示。
Toggle between Private Membership first build the project , end up with errors. Then build the project with Public Membership for all the frameworks appeared for Mantle.h file, you must get success.
在私有成员之间切换首先构建项目,最后出现错误。然后,为地幔出现的所有框架建立具有公共成员资格的项目。文件,你必须成功。
It is just a bug of building with multiple framework in Objective-C Swift project.
这只是Objective-C Swift项目中多框架构建的一个bug。
#1
205
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.
例如,它可能有一个测试目标,而另一个没有。对于这个特定的情况,您必须在测试目标中包含所有的类,或者不包含任何类。
#2
2
For me this error happened because I was trying to call a nested function. Only thing I had to do to have it fixed was to bring the function out to a scope where it was visible.
对我来说,这个错误发生是因为我试图调用一个嵌套函数。我要做的唯一一件事就是把这个函数放到一个可见的范围内。
#3
1
Because you haven't declared it. If you want to use a variable of another class you must use
因为你还没有声明。如果您想要使用另一个类的变量,则必须使用。
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var DestViewController : ViewController = segue.destinationViewController as ViewController
DestViewController.signedIn = false
}
You have to put this code at the end of the NewClass code
您必须将此代码放在NewClass代码的末尾
#4
1
Sometimes the compiler gets confused about the syntax in your class. This happens a lot if you paste in source from somewhere else.
有时编译器会对类中的语法感到困惑。如果从其他地方粘贴源文件,这种情况经常发生。
Try reducing the "unresolved" source file down to the bare minimum, cleaning and building. Once it builds successfully add all the complexity back to your class.
尝试将“未解决”的源文件减少到最少,清理和构建。一旦构建成功,将所有的复杂性添加回类中。
This has made it go away for me when re-starting Xcode did not work.
这使我在重新启动Xcode失败时不再使用它。
#5
1
Your NewClass
inherits from UIViewController
. You declared signedIn
in ViewController
. If you want NewClass
to be able to identify that variable it will have to be declared in a class that your NewClass
inherits from.
你的NewClass继承自UIViewController。你在ViewController中声明signedIn。如果希望NewClass能够识别该变量,则必须在NewClass继承的类中声明它。
#6
1
'Use of Unresolved Identifier' in Swift my also happen when you forgot to import a library. For example I have the error:
在Swift my中“使用未解析标识符”也会发生在您忘记导入库时。例如,我有一个错误:
In which I forgot the UIKIT
我忘了UIKIT
import UIKIT
进口UIKIT
#7
0
Another place I've seen this error is when your project has multiple targets AND multiple bridging headers. If it's a shared class, make sure you add the resource to all bridging headers.
我看到的另一个错误是当您的项目有多个目标和多个桥接头时。如果是共享类,请确保将资源添加到所有桥接头。
A good tip to is to look in the left Issue Navigator panel; the root object will show the target that is issuing the complaint.
一个很好的技巧是查看左边的问题导航面板;根对象将显示发出投诉的目标。
#8
0
If this is regarding a class you created, be sure that the class is not nested.
如果这与您创建的类有关,请确保该类没有嵌套。
F.e
F.e
A.swift
A.swift
class A {
class ARelated {
}
}
calling var b = ARelated()
will give 'Use of unresolved identifier: ARelated'.
调用var b = ARelated()将给出“使用未解析标识符:ARelated”。
You can either:
你可以:
1) separate the classes if wanted on the same file:
1)在同一个文件中,如果需要,将类分开:
A.swift
A.swift
class A {
}
class ARelated {
}
2) Maintain your same structure and use the enclosing class to get to the subclass:
2)保持相同的结构,使用封闭类到达子类:
var b = A.ARelated
var b = A.ARelated
#9
0
I did a stupid mistake. I forgot to mention the class as public or open while updating code in cocoapod workspace.
我犯了一个愚蠢的错误。在更新cocoapod工作空间中的代码时,我忘记将类作为公共的或开放的。
Please do check whether accesor if working in separate workspace.
请检查是否在单独的工作区工作。
#10
0
I got this error for Mantle Framework in my Objective-Swift Project. What i tried is ,
在我的Objective-Swift项目中,我得到了地幔框架的错误。我尝试的是,
- Check if import is there in Bridging-Header.h file
- 检查桥联页眉中是否有导入。h文件
- Change the Target Membership for Framework in Mantle.h file as shown in below screenshot.
- 在地幔中改变框架的目标成员。h文件如下截图所示。
Toggle between Private Membership first build the project , end up with errors. Then build the project with Public Membership for all the frameworks appeared for Mantle.h file, you must get success.
在私有成员之间切换首先构建项目,最后出现错误。然后,为地幔出现的所有框架建立具有公共成员资格的项目。文件,你必须成功。
It is just a bug of building with multiple framework in Objective-C Swift project.
这只是Objective-C Swift项目中多框架构建的一个bug。