Yes, you can apply for a residence permit if you are already in Sweden. You are required to apply for a temporary visitor permit. If you are not already eligible to stay in Sweden. You can later apply for the Sweden residence permit if you fulfill the eligibility criteria.