You have to use a pull back motion. So facing the direction you want to shoot, equip the slingshot. Touch onto your farmer and sliding your finger on the screen, draw back- drag in the opposite direction you want to shoot. A little red indicator should show the direction your shot will go. It fires when you release.
Since you can use wood, ore, coal, eggs, fruits, or veggies for ammo, I recommend practicing with something you have plenty of. The secret woods and easiest mine levels are good places to practice without too much danger.
To just get the walnut you may not need to actually practice. Just keep slinging in the general direction with whatever you have!
Also, if you use auto combat, your farmer will automatically use the sword if an enemy gets too close.