Swift에서 '미확인 식별자 사용'
그래서 저는 앱을 만들고 있었고 모든 것이 잘 작동했습니다. 하지만 오늘은 평소처럼 새 클래스를 만들었고 어떤 이유로이 클래스에서는 다른 클래스의 Public / Global 변수에 액세스 할 수 없습니다. 다른 모든 수업은 할 수 있지만 지금은 새 수업을 만들려고 할 때 할 수 없습니다. 이 문제는 어떻게 해결됩니까?
Swift와 Xcode 6을 사용하고 있습니다.
작업 클래스:
import UIKit
import Foundation
import Parse
import CoreData
var signedIn = true
class ViewController: UIViewController {
새로운 클래스 :
import UIKit
class NewClass: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
signedIn = false
}
하지만 signedIn = false
오류가 발생합니다.
확인되지 않은 식별자 "signedIn"사용
한 가지 가능한 문제는 새 클래스에 다른 대상과 다른 대상이 있다는 것입니다.
예를 들어 테스트 대상은 있지만 다른 대상은 없을 수 있습니다. 이 특정 경우에는 테스트 대상에 모든 클래스를 포함하거나 포함하지 않아야합니다.
Swift의 'Use of Unresolved Identifier'는 라이브러리 가져 오기를 잊었을 때도 발생합니다. 예를 들어 오류가 있습니다.
내가 잊은 UIKit
UIKit 가져 오기
나 에게이 오류는 중첩 함수 를 호출하려고했기 때문에 발생했습니다 . 나는 그것을 해결하도록해야했던 한가지는 기능을 가지고 있었다 밖으로 는 눈에 보였다 범위에.
당신이 그것을 선언하지 않았기 때문입니다. 다른 클래스의 변수를 사용하려면 다음을 사용해야합니다.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var DestViewController : ViewController = segue.destinationViewController as ViewController
DestViewController.signedIn = false
}
이 코드를 NewClass 코드 끝에 넣어야합니다.
때때로 컴파일러는 클래스의 구문에 대해 혼란스러워합니다. 다른 곳에서 소스를 붙여 넣으면 이런 일이 많이 발생합니다.
"해결되지 않은"소스 파일을 최소한으로 줄이고 정리 및 빌드하십시오. 성공적으로 빌드되면 모든 복잡성을 클래스에 다시 추가하십시오.
This has made it go away for me when re-starting Xcode did not work.
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.
I got this error for Mantle Framework in my Objective-Swift Project. What i tried is ,
- Check if import is there in Bridging-Header.h file
- Change the Target Membership for Framework in Mantle.h file as shown in below screenshot.
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.
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.
If this is regarding a class you created, be sure that the class is not nested.
F.e
A.swift
class A {
class ARelated {
}
}
calling var b = ARelated()
will give 'Use of unresolved identifier: ARelated'.
You can either:
1) separate the classes if wanted on the same file:
A.swift
class A {
}
class ARelated {
}
2) Maintain your same structure and use the enclosing class to get to the subclass:
var b = A.ARelated
나는 어리석은 실수를했다. cocoapod 작업 공간에서 코드를 업데이트하는 동안 클래스를 공개 또는 공개로 언급하는 것을 잊었습니다.
별도의 작업 공간에서 작업하는 경우 액세스 여부를 확인하십시오.
변수 선언을 잊었습니다. 그냥 var
앞에 넣어signedIn = false
참고 URL : https://stackoverflow.com/questions/28996730/use-of-unresolved-identifier-in-swift
'developer tip' 카테고리의 다른 글
헤더 및 클라이언트 라이브러리 부 버전 불일치 (0) | 2020.10.06 |
---|---|
JavaScript를 사용한 ASP.NET 포스트 백 (0) | 2020.10.06 |
네임 스페이스를 사용한 jQuery XML 구문 분석 (0) | 2020.10.06 |
휴지통으로 파일 보내기 (0) | 2020.10.06 |
8 비트 임베디드 시스템에서 사용할 수있는 flex / bison에 대한 대안이 있습니까? (0) | 2020.10.06 |