ios – Could not find an intent with identifier


I wanna add a toggle on widget in iOS 17, so I create a struct EditIntent

import Foundation
import AppIntents
import SwiftUI

@available(iOS 16.0, *)
struct EditIntent: AppIntent {
    
    static var title: LocalizedStringResource = "Edit intent"
    
    @Parameter(title:"Name")
    var name: String
    
    init(name: String) {
        self.name = name
    }
    
    init() {
        self.name = ""
    }
    
    func perform() async throws -> some IntentResult {
        
        return .result()
    }
}

Then use it in my widget

if #available(iOS 17.0, *) {
  Toggle(isOn: entry.isEditing, intent: EditIntent(name: entry.name)) {
   Text(entry.isEditing ? "Editing": "Save")
  }
}

But the console is Could not find an intent with identifier EditIntent, mangledTypeName: Optional("24WidgetExIntentsExtension10EditIntentV") when tapping the toggle. The code is so simple so that I don’t know where is the problem.
I’m running on 17.2 simulator

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img