How to Use textField input in a fetchRequest predicate

Hello:


I am trying to use textfield input in a fetchRequest predicate as follows:


@IBOutlet weak var gradeValue: NSTextField!
    @IBAction func saveNameGrade(_ sender: Any) {
        gradeValue.stringValue = nameGrade
    }

I want to use the value entered in the text field (gradeValue) and save it in the variable "nameGrade" then use "nameGrade" as the Predicate in my fetchRequest like so:


let predicate2 = NSPredicate(format: "grade = %@",nameGrade) 
print ("selected grade is \(nameGrade)")// returns nil


But this doesn't work.

Any help will be appreciated.

Problem Solved: Without the use of an IB Action Outlet.


let nameGrade = gradeValue.stringValue

How to Use textField input in a fetchRequest predicate
 
 
Q