小编Mik*_*e H的帖子

如何将 Swift 类传递给需要类的 Objective-C 方法?

我希望使用 Objective-C 库saxy将一些 XML 解析为对象,但是方法签名是:

+ (id)rootXPath:(NSString *)xpath toMany:(Class)toType nsURI:(NSString *)nsURI;
Run Code Online (Sandbox Code Playgroud)

我无法确定如何传递 Class 对象类型,因为 Swift 似乎无法以这种方式处理类。作为一种解决方法,我可能会在 Objective-C 中创建域模型 + 一个包装器,但如果知道是否有办法在纯 Swift 中做到这一点会很好。

我尝试了以下方法,但得到了 EXC_BAD_INSTRUCTION:

OXmlElementMapper.rootXPath("/route", toMany: Route.self, nsURI: "")
Run Code Online (Sandbox Code Playgroud)

这会产生语法错误:

OXmlElementMapper.rootXPath("/route", toMany: Route.Type, nsURI: "")
Run Code Online (Sandbox Code Playgroud)

swift

4
推荐指数
1
解决办法
2120
查看次数

如何将交换标头设置为路由的结果?

我有一个骆驼路线,它有一个步骤调用子路线将正文的文本部分转换为 PDF。不幸的camel-pdf是不保留标题。有没有办法在不丢失当前交换的情况下获得子路由的价值?

子路由

from("seda:generate-pdf")

// Back up the original in a header
.setHeader("original", body())

// Create the PDF
.to("pdf:create?textProcessingFactory=autoFormatting")
// UHOH! All my headers are gone :(

// Set the PDF as the header for the doc server
.setHeader("pdf", body())

// Move the indicator back to the body
.setBody(header("original")) // <-- this no longer exists
Run Code Online (Sandbox Code Playgroud)

主要路线

// Snip

// Unmarshal into Java

.unmarshal().json(JsonLibrary.Gson, MyReportContainingText.class)

// Call sub-route to generate the PDF
.inOut("seda:generate-pdf")
// UHOH! All my headers are …
Run Code Online (Sandbox Code Playgroud)

apache-camel

1
推荐指数
1
解决办法
5519
查看次数

标签 统计

apache-camel ×1

swift ×1