     }
     
     func textFieldDidEndEditing(_ textField: UITextField) {
+        guard let property = property else { return }
         if  property.type != .bool {
-            guard let del = delegate else {
+            guard let delegate = delegate, let text = textField.text else {
                 print("delegate not set")
                 return
             }
-            del.textFieldDidFinishEdit(textField.text!, property: self.property)
+            delegate.textFieldDidFinishEdit(text, property: property)
         }
         textField.resignFirstResponder()
     }

    // MARK: - UITextFieldDelegate
    
    func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
        return shouldAllowEditing()
    }
    
    private func shouldAllowEditing() -> Bool {
        return !property.isArray &&
            !(property.type == .data ||
                property.type == .linkingObjects ||
                property.type == .object)
    }
    
    func textFieldDidBeginEditing(_ textField: UITextField) {
        if  (property != nil) && (property.type == .bool) {
            
            let isEqual:Bool = (textFieldPropValue.text! as String == "false")
            var newValue = "0"
            if isEqual {
                newValue = "1"
                textField.text = "true"
            } else {
                textField.text = "false"
            }
            
            guard let del = delegate else {
                print("delegate not set")
                return
            }
            del.textFieldDidFinishEdit(newValue, property: self.property)
            textField.resignFirstResponder()
            setNeedsLayout()
        }

    }
}

protocol RBSRealmPropertyCellDelegate: AnyObject {
    func textFieldDidFinishEdit(_ input: String, property: Property)
}
