SwiftSummarize 是从字符串创建摘要的最简单方法。 在内部,它是 CoreServices SKSummary 的简单包装。
之前
致那些疯狂的人。那些格格不入的人。那些叛逆者。那些惹事生非的人。那些方孔里的圆钉。那些以不同方式看待事物的人。他们不喜欢规则。他们不尊重现状。你可以引用他们,不同意他们,赞美或诋毁他们。你唯一不能做的就是忽视他们。因为他们改变事物。他们推动人类前进。虽然有些人可能认为他们是疯子,但我们认为他们是天才。因为那些疯狂到认为自己可以改变世界的人,才是真正改变世界的人。
之后
因为那些疯狂到认为自己可以改变世界的人,才是真正改变世界的人
将此 URL 添加到您的依赖项
https://github.com/StefKors/SwiftSummarize
let input = """
Here's to the crazy ones. The misfits. The rebels. The troublemakers. The
round pegs in the square holes. The ones who see things differently. They're not
fond of rules. And they have no respect for the status quo. You can quote them,
disagree with them, glorify or vilify them. About the only thing you can't do is ignore
them. Because they change things. They push the human race forward. And while some
may see them as the crazy ones, we see genius. Because the people who are crazy
enough to think they can change the world, are the ones who do.
"""
let summary = Summary(text, numberOfSentences: 1)
print(summary.output)
// Because the people who are crazy enough to think they can change the world, are the ones who do
或者使用扩展直接在字符串上使用它
let input = """
Here's to the crazy ones. The misfits. The rebels. The troublemakers. The
round pegs in the square holes. The ones who see things differently. They're not
fond of rules. And they have no respect for the status quo. You can quote them,
disagree with them, glorify or vilify them. About the only thing you can't do is ignore
them. Because they change things. They push the human race forward. And while some
may see them as the crazy ones, we see genius. Because the people who are crazy
enough to think they can change the world, are the ones who do.
"""
let output = input.summarize(numberOfSentences: 1)
print(output)
// Because the people who are crazy enough to think they can change the world, are the ones who do
完整的 SwiftUI 代码示例可以在 /Example/ExampleSwiftUI.swift 中找到