【问题标题】:What do these characters in Swift mean <>. If I wrapped a keyword In them, what would that mean exactly [closed]Swift 中的这些字符是什么意思 <>。如果我在其中包含一个关键字,那究竟意味着什么[关闭]
【发布时间】:2020-03-30 01:12:36
【问题描述】:

例如,如果我有:

var hostingController: UIHostingController<Content>! = nil

当我将内容放在大于号和小于号内时,示例是什么意思?

【问题讨论】:

  • 这是一个通用定义
  • 对不起,我是 swift 新手。
  • 这将如何影响变量的后续实现。

标签: swift swiftui


【解决方案1】:

这是一个通用定义。当您编写可应用于许多不同类型的代码时,泛型很有用。 例如,这意味着 UIHostingController 可以用任何视图初始化。

 hostingController = UIHostingController.init(rootView: ContentView())

 struct ContentView: View {
    var body: some View {
       Text("some text")
   }
 }

希望这有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-23
    • 2016-05-18
    • 1970-01-01
    • 2010-12-12
    • 2013-11-30
    相关资源
    最近更新 更多