Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the native language setting for Swift or Objective-C in an existing Flutter project in Android Studio?

I've initially created a Flutter project with the native languages of Kotlin and Swift in Android Studio. Is there a way to change the native iOS language to Objective-C. This configuration only seems to occur on the creation of a Flutter project.

like image 639
Peter Birdsall Avatar asked Sep 15 '18 05:09

Peter Birdsall


People also ask

Does flutter use Objective C?

Flutter uses a flexible system that allows you to call platform-specific APIs in a language that works directly with those APIs: Kotlin or Java on Android. Swift or Objective-C on iOS. C++ on Windows.

What is the Swift programming language?

The first release of Swift took place in 2014. It was positioned as a faster and more efficient programming language for creating iOS and macOS applications. It has become the fastest-growing programming language in history. Unlike Objective-C, Swift was built for the average developer.

What programming language is used to make iOS apps?

Until 2014, all native iOS applications were created using Objective-C. Before the release of Swift, Objective-C was ranked 7th in the list of most popular programming languages. Some native applications are still being built using Objective-C, although Swift has become more popular for this.

How do I use swift types in Objective-C?

You can work with types declared in Swift from within the Objective-C code in your project by importing an Xcode-generated header file. This file is an Objective-C header that declares the Swift interfaces in your target, and you can think of it as an umbrella header for your Swift code.

How do you reference a swift header in Objective-C?

When declarations in an Objective-C header file refer to a Swift class or protocol that comes from the same target, importing the generated header creates a cyclical reference. To avoid this, use a forward declaration of the Swift class or protocol to reference it in an Objective-C interface.


2 Answers

  • For iOS the difference is mostly in ios/Runner.xcodeproj/project.pbxproj and some different source code files are generated in ios/Runner
    (the differences are too many to list them here)

  • For Android the differences are in android/build.gradle, android/app/build.gradle, and different source code files are generated in android/app/src/main

To switch languages you can delete the ios and/or android directory and run

flutter create -i swift -a kotlin .

If you made manual changes in files in these directories you need to re-apply them.

If you commit a project to Git and then switch language (as explained above), then it's easy to see what the differences are exactly.

like image 114
Günter Zöchbauer Avatar answered Nov 16 '22 03:11

Günter Zöchbauer


Don't delete the ios and android directories. doing so makes you loose all the changes and updates in your file. just this flutter create -i swift -a kotlin .

Don't forget the dot at the end , this specifies that you want to make the changes in the current directory not create a new one.

after you run this follow the instruction and your app will have Swift support for iOS and Kotlin for android.

To make sure that you have Swift support take a look at your runner folder and see if it contains

AppDelegate.siwft
like image 45
Dyary Avatar answered Nov 16 '22 02:11

Dyary