【问题标题】:Card simpleDescription() doesn't work in Apple's swift exampleCard simpleDescription() 在 Apple 的 swift 示例中不起作用
【发布时间】:2017-06-22 15:00:01
【问题描述】:

我正在实现 Apple 使用枚举创建卡片 struct 的示例,但 simpleDescription() 方法不起作用。苹果建议:

struct Card {
   var rank: Rank
   var suit: Suit
   func simpleDescription() -> String {
      return "The \(rank.simpleDescription()) of \(suit.simpleDescription())"
   }
}

但是当我打电话时

let card = Card(rank: .queen, suit: .hearts)
print("card = \(Card(rank: .queen, suit: .hearts))")

控制台打印出来

card = Card(rank: twoMatch.Rank.queen, suit: twoMatch.Suit.hearts)

其中“twoMatch”是我的应用程序的名称,忽略了我在simpleDescription() 中构造的字符串。我已经检查了几次方法签名,甚至从RankSuit 中的示例中复制了它,效果很好。

【问题讨论】:

  • 您定义了错误的方法。这只是 Apple 样本之一中的任意名称。请改为查看:stackoverflow.com/questions/24108634/…
  • 您能否发送您的完整代码,以及等级和西装定义。
  • @FernandoMazzon 我在自嘲。就是这样。我如何在评论中正式承认你??
  • @hkatz 如果您愿意,我会将其移至答案:)

标签: ios swift debugging


【解决方案1】:

您定义了错误的方法。这只是 Apple 样本之一中的任意名称。请改为查看:

What is the Swift equivalent of -[NSObject description]?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-01
    • 2012-07-02
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    相关资源
    最近更新 更多