Swift Compiler Error: Use of Unresolved Identifier 'Name'

Swift Compiler Error: Use of unresolved identifier 'name'

There could be a few possible issues.

  1. One of the classes has a Testing target and other one doesn't. You have to even include all of your classes in the testing target or none of them.

  2. If it's Objective C class, check that the class is in ObjectiveC bridging header file.

  3. If it's NSManagedObject subclass. Add @objc(className) before the class declaration.

  4. If it's part of a different framework, make sure that the class or function is public

Use of unresolved identifier 'questionList

If the questions are hard-coded move them into the Question struct as class property

struct Question {
let questionString: String
let answers: [String]
var selectedAnswerIndex: Int?

static let questionsList : [Question] = [Question(questionString: "What is your favorite type of food?", answers: ["Sandwiches", "Pizza", "Seafood", "Unagi"], selectedAnswerIndex: nil), Question(questionString: "What do you do for a living?", answers: ["Paleontologist", "Actor", "Chef", "Waitress"], selectedAnswerIndex: nil), Question(questionString: "Were you on a break?", answers: ["Yes", "No"], selectedAnswerIndex: nil)]

}

and call it from everywhere

Question.questionsList

Error: Use of unresolved Identifier 'Process'

Process was changed to CommandLine in swift 3.0

Try replacing Process with CommandLine


Here is the link to the commit that changed it:
Rename Process to CommandLine [SE-0086].

Swift - Use of unresolved identifier 'self' - from Closure in a Class

Rahul's explanation is correct, but the suggested answer is ever so slightly incomplete.

Here is a complete solution:

  1. Declare the doSomething property as lazy as Rahul suggested. A lazy stored property is a property whose initial value is not calculated until the first time it is used. In other words this closure will not be evaluated until the doSomething property is called at run-time, at which point self is guaranteed to exist. See Lazy Stored Properties in the Swift Programming Language for more details.

  2. Add a type annotation to the doSomething property so the compiler doesn't have to infer the type at compile time, which apparently it can't do because the closure includes self. See Type Safety and Type Inference in the Swift Programming Language for more details.

So the complete declaration is:

...
lazy var doSomething: (Data?, URLResponse?, Error?) -> Void = { (data: Data?, response: URLResponse?, error: Error?) -> Void in
...

ps. Welcome to Swift programming! It's a fantastic language and really fun. I hope you enjoy it as much as I do.

Use of Unresolved Identifier' in Swift

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



Related Topics



Leave a reply



Submit