【发布时间】:2017-11-16 19:57:42
【问题描述】:
我在这里做了一个结构
struct dicStruct<T,U>{}
这里是我的实例
var instanceOfDicStruct:dicStruct<Int,String> = dicStruct()
isEmpty 在这里不起作用,任何人都可以解释一下给我一些参考吗?
instanceOfDicStruct.isEmpty
【问题讨论】:
-
Would = nil work
-
是的 Nil 工作但我需要知道为什么 isEmpty 不只是为了兴趣而工作。
-
您定义了自己的类型
dicStruct,但没有isEmpty方法。不确定您的预期。 -
请注意,这是 Swift 约定以大写字母开头的结构命名。您应该花点时间阅读 Apple Swift Book itunes.apple.com/us/book/the-swift-programming-language-swift-4/…。你可能想要达到的是
struct MyStruct { var instancePropertyOfMyStruct: [Int: String] = [:] } var instanceOfMyStruct = MyStruct() instanceOfMyStruct.instancePropertyOfMyStruct.isEmpty// true -
哇,我也是 Rush 的忠实粉丝,我也是音乐家 xD 顺便说一句,我使用 swift 约定仍然无法正常工作..我知道我在 swift 中做什么是新的,我只是想学习swift type Struct ..谢谢
标签: swift