Fetch a name from core data and print it

I am trying to fetch a core data string from binary data. I am trying to use func getText to do this but I am getting an error stating Type of expression is ambiguous without more context at let imageData = Person[textNo].name!. I also have the singleton. I would like to print ideally the first saved name in core in the debug section. The data saves fine.



**extension** Person {

**@nonobjc** **public** **class** **func** fetchRequest() -> NSFetchRequest<Person> {

**return** NSFetchRequest<Person>(entityName: "Person")

}

**@NSManaged** **public** **var** name: String?

**@NSManaged** **public** **var** ssn: Int16

}



class ViewController: UIViewController {
 func getText(textNo:Int) {
        // first check the array bounds
      
        let info = helpText.shareInstance.fetchText()
    
        if info.count > textNo {
            
            
            
            if let imageData = Person[textNo].name!
            {
                print(imageData)
                
            } else {
                // no data
                print("data is empty Textss")
            }
        } else {
            // image number is greater than array bounds
            print("you are asking out of bounds")
        }
    }
  

  
  //insert
  func save(name: String, ssn : Int16) {
    
    let person = CoreDataManager.sharedManager.insertPerson(name: name, ssn: ssn)
    
    if person != nil {
      people.append(person!)
    
    }
  }
  
  override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
      save(name: "joe", ssn: 3343)}

Welcome to the Community, @timswift ! We’re glad to have you here.

Thank you for posting your question and seeking help from the forum. We will do our best to assist you with your coding query.

Don’t hesitate to ask any further questions or provide additional details to help us understand your issue better.

@marinbenc any feedbacks on @timswift questions would be appreciated

This topic was automatically closed after 166 days. New replies are no longer allowed.