tjarvstrand
tjarvstrand

Reputation: 1038

Using AppCode with Flutter plugin

How can I use AppCode for the ios-specific parts of my Flutter plugin?

I've created the plugin with flutter create --template=plugin --platforms=ios myplugin

The command doesn't generate an XCode project or workspace for the plugin itself but it includes an example app for which it does generate these. Running flutter build ios in example then creates symlinks to the plugin code in example/ios/.symlinks that I can use to edit the actual Swift code with auto completion, code navigation etc. When I open these files in AppCode however, I get the below error and no coding assistance is available at all:

enter image description here

Upvotes: 3

Views: 466

Answers (1)

Ben Butterworth
Ben Butterworth

Reputation: 28478

I previously used AppCode quite a lot to maintain some Flutter plugins' iOS code (but switched jobs and didn't need AppCode or Xcode). However, I recently started making a free app, and also wanted to contribute to a Flutter plugin for iOS, I wanted AppCode again. I got AppCode working again, so I wanted to share.

In your flutter directory:

  • For editing/debugging/running Flutter apps' iOS code: run appcode ios
  • For Flutter plugins, run appcode example/ios (not appcode ios)

Some principles:

  • The files don't show up immediately, use Command + Shift + O to find your file. Then Opt + F1 to show it in the project navigator.
  • Built at least once using flutter run or Xcode (to make sure configuration is set up).
  • You cannot escape Xcode. Xcode and AppCode are complementary. Find the balance 😂🤓. Refactoring code, debugging the application, searching and reading code works really well in AppCode. Xcode does reading configuration better or debugging builds.
  • If you get random errors (e.g. everything fails but the error is build failed in AppCode, you should open in Xcode or build/run the flutter app for iOS: flutter run and read the error messages.
  • If you want to debug both Flutter and iOS simultaneously, start the iOS debugger, then "Flutter attach" in android studio (maybe this is possible in VSCode too, but I don't use that).

Here's an example screenshot of AppCode with debugger working. You might be curious if telemetry flag you set in Flutter was actually being set in the iOS side... maybe there's a bug. But I take privacy seriously and confirm the telemetry is disabled. I also watch network traffic sometimes. 😂. If you're interested, you can then follow that to it's dependencies (manually, using by reading package.swift), and find out it is set to true by default.

        UserDefaults.standard.register(defaults: [
            #keyPath(UserDefaults.MGLMapboxMetricsEnabled): true
        ])

AppCode screenshot with debugger

Upvotes: 0

Related Questions