Monday, November 9, 2026
HomeiOS Developmentswift - The place and Learn how to Embody File Assets Inside...

swift – The place and Learn how to Embody File Assets Inside IOS part of Flutter Plugin?

[ad_1]

For example you are writing the IOS part of a Flutter plugin in Swift.

You have got your MyFlutterPlugin.swift file open in XCode.

In order that we all know what we’re speaking about the identical factor, it is the file that appears like this:

public class MyFlutterPlugin: NSObject, FlutterPlugin {

    public static func register(with registrar: FlutterPluginRegistrar) {
        let channel = FlutterMethodChannel(title: "my_flutter_plugin", binaryMessenger: registrar.messenger())
        let occasion = SwiftMetronomeFlutterPlugin()
        registrar.addMethodCallDelegate(occasion, channel: channel)
    }

    public func deal with(_ name: FlutterMethodCall, outcome: @escaping FlutterResult) {

    // ...

    }

}

This file exists on disk at:

[your_plugin_project_name]/ios/lessons/MyFlutterPlugin.swift

How may you add a useful resource, for instance an audio (WAV) file, such that it could possibly be referenced from inside MyFlutterPlugin.swift?

In a traditional (not Flutter) IOS app, I’ve achieved this by merely dragging the WAV file into XCode the place it sits alongside ViewController.swift, and referenced it from throughout the ViewController like this:

let clack_Path = Bundle.essential.path(forResource: "clack", ofType: "wav")
let clack_URL = URL(fileURLWithPath: clack_Path!)

However, if I strive that very same strategy from inside this Flutter Plugin (placing the audio file alongside MyFlutterPlugin.swift), I get an error that clack_Path is null.

So the place is the proper place to place the file, and learn how to correctly reference it?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments