9.1 C
London
Sunday, December 17, 2023

ios – Easy methods to move a varible to AppIntent in Swift


This can be a view which accommodates ‘information’ variable which is handed to trignext AppIntent.
Kindly assist me move it to AppIntent and replace its worth with the information coming from methodology channel.

import SwiftUI

struct widget_testEntryView: View {
    @State var information: String = "Leja Re"
    var entry: Supplier.Entry

    var physique: some View {
        ZStack {
            Colour(UIColor(crimson: 0x73, inexperienced: 0x46, blue: 0x56))
            VStack(alignment: .main) {
                Spacer().body(top: 40)
                HStack {
                    Spacer().body(width: 20)
                    Picture("Picture")
                        .resizable()
                        .body(width: 60, top: 60)
                        .cornerRadius(10)
                    VStack {
                        HStack {
                            Spacer()
                            Picture(systemName: "backward.finish.fill")
                                .foregroundColor(.white)
                                .body(width: 20, top: 20)
                            Spacer().body(width: 20)
                        }
                        Spacer()
                    }
                }
                HStack {
                    Spacer().body(width: 20)
                    VStack {
                        Spacer().body(width: 0, top: 2)
                        Textual content(information)
                            .font(.system(measurement: 15))
                            .foregroundColor(.white)
                        Spacer().body(width: 0, top: 2)
                        Textual content("Dhvani")
                            .font(.system(measurement: 15))
                            .foregroundColor(.grey)
                        Spacer().body(width: 0, top: 5)
                    }
                }
                HStack {
                    Spacer().body(width: 25)
                    Button(motion: {
                        // Deal with Earlier button motion
                    }) {
                        Label("Earlier", systemImage: "backward.fill")
                            .padding()
                            .foregroundColor(.white)
                            .body(width: 10, top: 10)
                    }
                    Spacer()
                    Button(motion: {
                        // Deal with Pause button motion
                    }) {
                        Label("Pause", systemImage: "pause.fill")
                            .padding()
                            .foregroundColor(.white)
                            .body(width: 10, top: 10)
                    }
                    Spacer()
                    Button(motion: {
                        handleNext()
                    }) {
                        Label("Subsequent", systemImage: "ahead.fill")
                            .padding()
                            .foregroundColor(.white)
                            .body(width: 10, top: 10)
                    }
                    Spacer().body(width: 25)
                }
                Spacer().body(top: 20)
            }
        }
    }

    func handleNext() {
        Activity {
            do {
                let outcome = strive await trignext(information: $information).carry out()
            } catch {
                print("Error dealing with subsequent: (error)")
            }
        }
    }
}

That is the AppIntent which updates the worth of information variable, right here its giving error when @binding is used, it doesn’t enable to move the information variable.

import Intents

struct trignext: AppIntent {
    static var title: LocalizedStringResource = "Subsequent Music"
    static var description = IntentDescription("Orders a soup out of your favourite restaurant.")
    
    @Binding var information: String

    init(information: Binding<String>) {
        _data = information
    }

    func carry out() async throws -> some IntentResult {
        let updatedData = strive await NativeMethodChannel.triggerNext()
        
        DispatchQueue.principal.async {
            information = updatedData ?? "Default Information"
        }
        
        return .outcome(worth: information)
    }
}

That is the AppIntent which updates the worth of information variable, right here its giving error when @binding is used, it doesn’t enable to move the information variable.

Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here