swiftcore-dataxcode8nsmanagedobject

Swift: "Expected expression after operator" error in NSManaged while trying to push a record to entity


I've an entity where there are 4 string attributes. I'm trying to push a record into the entity but I'm facing 'Expected Expression after operator' error in record line.

   guard
        let appDelegate = UIApplication.shared.delegate as? AppDelegate
        else {
            return
    }
    let managedContext = appDelegate.persistentContainer.viewContext
    //2
    let entity = NSEntityDescription.entity(forEntityName: "Details", in: managedContext) !
    //3
    let record = NSManagedObject(entity: entity, insertInto: managedContext)

Solution

  • This line

    let entity = ....... "Details", in: managedContext)!   /// ! should be beside the line