Counting the amount of attributes saved from core data helper class

n my swift code below the goal is to get the amount of core data attributes saved into core data. I am receiving the error message No exact matches in call to initializer at indexBox.text = String(info?) . I don’t know what to do next.

class ViewController: UIViewController {
  override func viewDidLoad() {
        super.viewDidLoad()
   let info = CoredataHandler.fetchObject()?.count
        
 
        
            indexBox.text = String(info?)
        
     
        
     
        
    }
}



class CoredataHandler : NSManagedObject {
    class func fetchObject() -> [User]?
    {
        let context = getContext()
        var user : [User]? = nil
        do {
            user = try context.fetch(User.fetchRequest())
            
            return user
            
        } catch {
            return user
        }
        
    }
    
}

Set a breakpoint in that line and check the value for info. Is it nil? if so, then you should have a coalescent value for when there isn’t a value there to display:

info ?? 0

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