SuperAPI AI 工具集

axiom-transferable-ref

智能体与模型

查看项目

更新于 10-16 00:23

技能介绍

用途:为 SwiftUI 开发者提供 CoreTransferable 框架与系统共享入口(拖放、复制/粘贴、ShareLink)的完整参考。

主要能力:

  • 让自定义类型遵循 Transferable,选择 CodableRepresentation、DataRepresentation、FileRepresentation 或 ProxyRepresentation;
  • 组合多种表示并按“最丰富优先”排序,可用 .exportingCondition 与 .visibility 控制导出;
  • 声明自定义 UTType 并在 Info.plist 配置 UTExportedTypeDeclarations;
  • 使用 .draggable、.dropDestination、.copyable、.pasteDestination、.cuttable、PasteButton 等 SwiftUI 视图修饰符;
  • 通过 NSItemProvider.loadTransferable 与 UIKit 桥接,必要时改用 UIActivityViewController。

必要用法要点:

  • Transferable 需实现 static var transferRepresentation;
  • FileRepresentation 的 received.file 仅有临时沙箱权限,导入闭包内必须复制到自有存储;
  • 内容类型尽量具体(如 .png、.movie),避免 UTType.data;
  • 自定义 UTType 必须在 Info.plist 同步声明,否则跨应用传输静默失败。

适用场景:应用内与应用间拖放、剪贴板操作、系统分享,以及跨 UIKit 的内容交换。

限制:.copyable、.pasteDestination、.cuttable 仅 macOS 13+;iOS 需改用 PasteButton(iOS 16+)或 UIPasteboard。PasteButton 在 iOS 会自动校验剪贴板变化,macOS 不会。其余平台与版本细节资料未提供。