Swinging an object is actually a very difficult task because it requires an understanding of the object's friction and center of mass. MIT researchers have managed to design Swingbot, a robot that can gather this necessary information by tilting and shaking the object before trying to swing it.
Paper: http://gelsight.csail.mit.edu/swingbot/IROS2020_SwingBot.pdf
Project page: http://gelsight.csail.mit.edu/swingbot/