If you are going to study at a university or college in Sweden for longer than three months, you must have a residence permit. The permit must be in place before you travel to Sweden.
Read more about the application process at the Swedish Migration Agency’s website.