The switch comes first in the new part of the circuit and new 2 wire cable is run to it from the outlet.
New ceiling light and wall switch from existing wall receptacle.
This can often be the easiest and most likely solution to access a source for a new receptacle or a switch to a new light fixture.
If the new outlet is on the same wall as the switch and the two are close enough you might consider removing some drywall and patching the wall when you re done running the cable.
Mark this wire black.
Set the new outlet box in the same wall space as the existing one to simplify running the cable.
Then splice the fixture s black lead into the new black wire.
I did the same with the white jumper to where the white wire was previously on the outlet.
In this example a new wall receptacle can be installed using an existing receptacle in an adjacent room.
To wire the ceiling fixture to the new wall switch first connect the copper grounding wire to the fixture.
If you need to provide power to an outlet or another switch you can tap into either the live wire from the panel on the existing wall switch or the switched wire should you desire that the new.
If the outlet is too far away for that most electricians feed the cable into the attic or basement drilling a hole in the top or bottom plate of the wall as needed.
Put a 6 black pigtail on a brass screw and a 6 white pigtail on a white screw.
Finally i tied my black jumper to the screw on outlet that held the previous black wire.
Then wirenut all the white wires together.
Wiring a new ceiling light and switch from an existing power source from what has been described in this question it appears that a neutral wire is not available at the wall switch.
The neutral for the new light is taken from the receptacle and spliced to the new white wire and to a pigtail that connects back to the receptacle.
That should make the receptacle work at all times.
Regardless of how they were arranged before.
I tied the ground from the new romex to a screw inside the existing metal outlet box.
After removing the black wire to the fixture s lead splice it into the new white wire.
The ceiling light fixture requires a neutral for the light to work and your wall switch box does not have a neutral wire available so additional wiring will be required to obtain the neutral wire from the outlet.