我正在尝试在Swift中为macOS AddressBook创建一个最小动作插件 . 我的出发点是Xcode创建的ObjC默认模板,它包含

ContactsActionPluginObjC.h
ContactsActionPluginObjC.m

Info.plist

我所做的是从Xcode项目中删除 ContactsActionPluginObjC.hContactsActionPluginObjC.m ,并在其位置添加 SwiftFile.swift

import Cocoa
import AddressBook

class SwiftFile {
    func actionProperty() -> String! {
        return kABPhoneProperty
    }

    func title(for: ABPerson!, identifier: String!) -> String! {
        return "SomeText"
    }

    func performAction(for: ABPerson!, identifier: String!) {
        return
    }

    func shouldEnableAction(for: ABPerson!, identifier:String!) -> Bool {
        return true
    }
}

我还将 Info.plist 中的 Principal class 调整为 SwiftFile . 这种构建没有错误 . 但是,当我将生成的 .bundle 文件复制到 ~/Library/Address Book Plug-Ins 然后启动macOS Contacts时,该插件不会显示在联系人电话号码的上下文菜单中 .

将已编译的ObjC模板的 .bundle 文件放在同一位置,基于ObjC的操作按预期显示 .

缺少什么/我忽略了什么:为什么Swift版本不起作用?