A generalization of the Swartz equality