Search code examples
swiftmacosshortcut

On macOS Monterey, cannot create shortcut actions


I'm trying to follow the Meet Shortcuts for macOS and I keep getting stuck on the stack where you have

class IntentHandler: NSObject, CreateTaskIntentHandling {
    func handle(intent: CreateTaskIntent, completion: @escaping (CreateTaskIntentResponse) -> Void) {
        let title = intent.title!
        let dueDate = intent.dueDate!
    
        let task = createTask(name: title, due: dueDate)
    
        let response = CreateTaskIntentResponse(code: .success, userActivity: nil)
        response.task = task
        completion(response)
    }
}

The problem is the line let task = createTask(name: title, due: dueDate) where is that suppose to come from, also its type is Task which is already defined, so I trained using a different name, I don't know how I am suppose to create the CreateTaskIntentResponse.task class, and there doesn't seem to be any instruction to do so, I also had a few problems with it all being beta so there would be different versions of the same method, and a field in the intent file needed to be fill in.


Solution

  • Ok this is what the createTask function is suppose to look like

    func createTask(name: String, due: DateComponents) -> Task {
        let task = Task(identifier: "<appid>.createTask", display: name)
        task.dueDate = due
        return task
    }
    

    Where appid is your application id I think.