我正在尝试使用自定义类型标识符在macOS上实现拖放操作,以避免发生冲突,但它似乎不起作用。首先,这是一个具有 public 和已知标识符的工作示例:
2020-04-15 15:30:34 ERROR TransportResponseHandler:144 - Still have 1 requests outstanding when connection from /10.101.3.128:6066 is closed
2020-04-15 15:30:34 WARN StandaloneAppClient$ClientEndpoint:87 - Failed to connect to master 10.101.3.128:6066
org.apache.spark.SparkException: Exception thrown in awaitResult:
at org.apache.spark.util.ThreadUtils$.awaitResult(ThreadUtils.scala:205)
at org.apache.spark.rpc.RpcTimeout.awaitResult(RpcTimeout.scala:75)
at org.apache.spark.rpc.RpcEnv.setupEndpointRefByURI(RpcEnv.scala:101)
at org.apache.spark.rpc.RpcEnv.setupEndpointRef(RpcEnv.scala:109)
at org.apache.spark.deploy.client.StandaloneAppClient$ClientEndpoint$$anonfun$tryRegisterAllMasters$1$$anon$1.run(StandaloneAppClient.scala:106)
....
在此示例中,您可以将上面的图像拖动到放置区域中,它将打印出提供程序。现在,仅更改struct ReleaseView: View {
let id: Int
var body: some View {
GeometryReader { _ in
VStack(spacing: 16) {
Image(nsImage: NSImage(named: NSImage.networkName)!)
.contentShape(Rectangle())
.onDrag {
return NSItemProvider(item: "\(self.id)" as NSString, typeIdentifier: NSPasteboard.PasteboardType.string.rawValue)
}
DropZone()
}
}
}
}
struct DropZone: View {
@State var isDragging = false
var body: some View {
RoundedRectangle(cornerRadius: 16)
.stroke(style: StrokeStyle(lineWidth: 4, dash: [8, 8]))
.background(isDragging ? Color.secondary : Color.clear)
.frame(width: 100, height: 100)
.onDrop(of: [NSPasteboard.PasteboardType.string.rawValue], isTargeted: self.$isDragging) { itemProvider in
print(itemProvider)
return true
}
}
}
会破坏一切。
typeIdentifier
现在这不起作用。在这里使用相同的常量,因此它不是字符串不匹配。只是另一个SwiftUI错误?
答案 0 :(得分:3)
上面的typeIdentifier
不仅仅是唯一的字符串,它必须是UTI 。
如果您要使用某些特定于自定义应用程序的UTI(如果确实需要,请三思而后行),则必须根据Apple规则从
开始注册一个。<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeIdentifier</key>
<string>com.procrastin8.plzwork</string>
...
在应用Info.plist