This is a one-way street. You can configure the application to NSUIElement to hide the dock icon, and then call [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
to show it in the dock, but after that you cannot delete it. This way, you can make the dock icon a custom user, but you have to restart the application to hide the icon.
EDIT
You can call setActivationPolicy:NSApplicationActivationPolicyProhibited
to hide the dock icon again - user1592530 Sep 18 12 at 2:21 pm
The comment is correct. There are two ways these days - Daij-Djan Dec 24 '12 at 11:46
source share