【问题标题】:Weird syntax in swiftswift中的奇怪语法
【发布时间】:2018-12-08 05:09:56
【问题描述】:

我查看了 Eureka 项目,发现它们有一些奇怪的语法,比如 <<<+++,这似乎不是常见的 swift 语法,谁能解释更多?

【问题讨论】:

  • 请不要将代码图片粘贴到您的问题中。只需粘贴代码即可。
  • 它们是自定义运算符,都意味着向表单、部分或数组添加一些内容。您可以通过在 Xcode 的 Find Navigtor (Cmd + 4) 或 on Github 中搜索 infix operator +++ 来查看它们的定义。
  • 这能回答你的问题吗? What is +++ and <<< on Swift?

标签: swift


【解决方案1】:

很难找到有关自定义运算符的信息,这就是为什么您通常不应该定义自定义运算符的原因。

无论如何,Eureka 自定义操作符都记录在案here

运营商

Eureka 包含自定义运算符,使表单创建变得容易:

+++       添加一个部分

form +++ Section()

// Chain it to add multiple Sections
form +++ Section("First Section") +++ Section("Another Section")

// Or use it with rows and get a blank section for free
form +++ TextRow()
     +++ TextRow()  // Each row will be on a separate section

form +++ Section()
        <<< TextRow()
        <<< DateRow()

// Or implicitly create the Section
form +++ TextRow()
    <<< DateRow()

+=        追加一个数组

// Append Sections into a Form
form += [Section("A"), Section("B"), Section("C")]

// Append Rows into a Section
section += [TextRow(), DateRow()]

【讨论】:

  • 我认为可以选择运算符并跳转到定​​义,不是吗?
  • 这一直有效。不知道现在有没有。但如果你想谷歌了解更多信息,祝你好运……
【解决方案2】:

这些运算符不是 Swift 的一部分。它们在该项目中定义,并且仅在项目中有意义。

看看

https://github.com/xmartlabs/Eureka/blob/master/Source/Core/Operators.swift#L27

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AdvancedOperators.html

您可以创建自定义运算符。

【讨论】:

    猜你喜欢
    • 2015-12-22
    • 1970-01-01
    • 1970-01-01
    • 2013-09-05
    • 2017-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多