【问题标题】:How do you initialise Nested Structures and run methods within nested structures in Swift?如何在 Swift 中初始化嵌套结构并在嵌套结构中运行方法?
【发布时间】:2015-03-08 11:45:10
【问题描述】:

我有一个班级。该类具有结构变量,其中一些结构具有结构作为变量和方法。

当我运行程序并通过调试时,我可以看到我的类变量,但作为结构的变量只是 nil。

我已将所有类定义和结构定义作为屏幕截图以及我的调用和调试屏幕包含在内...任何帮助都会很棒。

试图打电话

CLASS--> Struct(Details)-->Struct(Location)-->StructMethod(ConfigLocation)

好的,这里是屏幕截图。

和代码。

【问题讨论】:

  • 请粘贴代码而不是屏幕截图。因此,答案可以轻松地尝试在他们的环境中修改您的代码。

标签: ios xcode class swift struct


【解决方案1】:

尝试:

struct SV_StinkDetails_Model {

    // ...

    var SV_StinkDetails_Location:SV_StinkLocation_Model! = SV_StringLocation_Model()
    //...                                                    Just remove `?` here ^

SV_StinkLocation_Model?() 表示Optional<SV_StinkLocation_Model>()。这将返回 nilSV_StinkLocation_Model? 类型。

【讨论】:

  • 这确实帮助并让我通过了第一个障碍.. 我现在可以看到里面的详细信息。但是,它在我对 Location 的调用中给了我一个错误,现在说它期望我的位置内的变量作为对 create location 结构的调用的一部分? var SV_StinkDetails_Location:SV_StinkLocation_Model! = SV_StinkLocation_Model() 给我错误:调用中缺少参数 SV_StinkLocation_Longitude? SV_StinkLocation_Longitude 是结构体 SV_StinkLocation 中的一个变量。如果我删除该变量,它会给我下一个变量同样的错误?! @rintaro ?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-18
相关资源
最近更新 更多