Note: The three tildes can be replaced with x, y and z coordinates, respectively.
bob can be replaced with any name, spaces are acceptable.
Also, replace the 1 with 0 if you want the name to be visible only when you're looking directly at the pig, or leave it as 1 if you want the name to be visible at all times.
How are you able to spawn a pig named something using a command?
/summon Pig ~ ~ ~ {CustomName:bob,CustomNameVisible:1}
Note: The three tildes can be replaced with x, y and z coordinates, respectively.
bob can be replaced with any name, spaces are acceptable.
Also, replace the 1 with 0 if you want the name to be visible only when you're looking directly at the pig, or leave it as 1 if you want the name to be visible at all times.
Hope I helped
Cheers! -TheEpicGabriel0