How to Enable Swift Support For Existing Project In Flutter

How to Enable Swift Support For Existing Project In Flutter??

Sometimes when the user is developing a flutter project user needs to way to enable swift support for the flutter project. So in this article, we will go through how to Enable Swift Support For Existing Project In Flutter.

How to Enable Swift Support For Existing Project In Flutter??

In order to solve this error we need to make changes like the below:

  • Delete existing ios folder from the root of flutter project.
  • Run this command flutter create -i swift.

This command will create only an ios directory with swift support.

You can also try the below way:
  • For swift support, you need to move your ios folder to outside of your project folder, for kotlin move outside the android folder, also check your package name in your manifest, or your PRODUCT_BUNDLE_IDENTIFIER
  • Run the below flutter command in your terminal on the root folder of your project.
  • -i swift is for swift
  • -a kotlin is for kotlin.
  • –org is to set the first two words of your package, in this case, com.custom_name
  • –project-name is to set the last word of your package in this case my_proyect
You can use only swift/kotlin or both
flutter create -i swift -a kotlin --org com.custom_name --project-name my_proyect .
  • Apply again your previous custom changes on the ios folder E.g: info.plist, custom splash screen, etc., now in the Runner folder you don’t have main.m and AppDelegate.h files, instead, you have only the AppDelegate.swift file in swift language, so if you need to put API_KEYs there, the code is different.
  • If you apply the -a kotlin line, is the same logic that swift in your android folder, so your MainActivity.java file is now a MainActivity.kt file in the kotlin language, and you need to apply again your previous custom changes in Android folder E.g: build.gradle, res folder, android_manifest, etc.

You can run flutter create. in your flutter app directory and it will repair the project, recreating any files that are missing.

So if you already have a project created with Objective-C and Java, you can run:

flutter create -i swift -a kotlin .

to convert the host app to Kotlin and Swift.

For the scenario where you already have an ios module partially written in Objective-C, and now just want to use Swift code alongside.

It is suggested that you right-click on ios in the project window. Now choose the Open iOS module in XCode this from the context menu.

iOS flutter
iOS flutter

Then you can just follow those instructions: Here

If your plan is to rewrite the module in swift then create a new project with the same name as your original one and turned on Swift support. Then I’d just copy the whole ios module to your original project.

Conclusion:

Thanks for being with us on a Flutter Journey !!!

So Today, We learned how to Enable Swift Support For Existing Project In Flutter.

Don’t forget to drop your feedback in the comments right below 🙂

Flutter Agency is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc.

Flutter Agency is one of the most popular online portals dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge of Flutter.

Flutter Agency

Written by Flutter Agency

We are a dynamic team specializing in building scalable apps and software, merging innovation and design with efficiency. Our focus is on delivering comprehensive, user-friendly solutions for both app and web development, catering to businesses of all sizes.

Leave a comment

Your email address will not be published. Required fields are marked *


Discuss Your Project

Connect with Flutter Agency's proficient skilled team for your app development projects across different technologies. We'd love to hear from you! Fill out the form below to discuss your project.

Have Project For Us

Get in Touch

"*" indicates required fields

ready to get started?

Fill out the form below and we will be in touch soon!

"*" indicates required fields